Click here to Skip to main content
15,884,388 members
Home / Discussions / Visual Basic
   

Visual Basic

 
QuestionDeleting a sent file Pin
Member 1152288212-Feb-21 11:11
Member 1152288212-Feb-21 11:11 
AnswerRe: Deleting a sent file Pin
Ralf Meier12-Feb-21 12:26
mveRalf Meier12-Feb-21 12:26 
AnswerRe: Deleting a sent file Pin
Dave Kreskowiak12-Feb-21 15:51
mveDave Kreskowiak12-Feb-21 15:51 
AnswerRe: Deleting a sent file Pin
Richard Deeming14-Feb-21 21:51
mveRichard Deeming14-Feb-21 21:51 
Questionwkhtmltopdf.exe - Process-Start over COM-Interop - Access denied Pin
VoidFunctionMain10-Feb-21 4:48
VoidFunctionMain10-Feb-21 4:48 
QuestionCode for Saving work Pin
Wamono erick5-Feb-21 7:52
Wamono erick5-Feb-21 7:52 
AnswerRe: Code for Saving work Pin
Dave Kreskowiak5-Feb-21 8:28
mveDave Kreskowiak5-Feb-21 8:28 
QuestionProblem when setting the ReadOnly state of a property: CLOSED Pin
mo149231-Jan-21 5:56
mo149231-Jan-21 5:56 
Aaaaaaaaaaaaaaaaaarg! As usual once I post I figure it out.
The PropertyGrid does not maintain the state. It has to be reloaded. How Dumb.
Sorry

Hello all,
I have a problem where the PropertyGrid does not update a property when changing a property to ReadOnly and not ReadOnly. The problem occurs when I have 2 controls of the 'same type'.

Below is test code which contains all of the things I have tried to refresh the PropertyGrid with no success.

When Control1 is loaded into the PropertyGrid I change the DesignLocked state and update the ReadOnly state of the PostPrintString to Readonly or not ReadOnly depending on the DesignLocked Value. This works in Control1.

However, after I have changed the value in Control1 and then select Control2 into the PropertyGrid (through a button click in MainForm), the PostPrintString property in the grid maintains the same ReadOnly state of Control1.

I've tried a number of things I've seen on google including NotifyParentPropertyAttribute with no success.

I would appreciate any help with this.
Thank you

This is the test code in MainForm to load each control.

Private Sub Ctrl1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles ctrl1.Click
Me.PropertyGrid1.SelectedObject = Nothing
Me.PropertyGrid1.Refresh()
Me.PropertyGrid1.SelectedObject = Me.ctrl1
Me.PropertyGrid1.Refresh()
End Sub

Private Sub Ctrl2_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles ctrl2.Click
Me.PropertyGrid1.SelectedObject = Nothing
Me.PropertyGrid1.Refresh()
Me.PropertyGrid1.SelectedObject = Me.ctrl2
Me.PropertyGrid1.Refresh()
End Sub

Below is the test code in a UserControl that shows what I do when I change the DesignLocked property.

Imports System.ComponentModel
Imports System.Reflection
Public Class TestUserControl

' Gets loaded with MainForms PropertyGrid
Public _PropertyGrid As PropertyGrid

<CategoryAttribute("AA"), _
EditorBrowsable(EditorBrowsableState.Always), _
DesignerSerializationVisibility(DesignerSerializationVisibility.Visible), _
Browsable(True), _
[ReadOnly](False), _
BindableAttribute(False), _
DefaultValueAttribute(""), _
DesignOnly(False), _
DescriptionAttribute("")> _
Public Property PostPrintString() As String
Get

Return ""

End Get
Set(ByVal value As String)
End Set
End Property


''' <summary>
''' Get/Set local DesignLocked state
''' </summary>
''' <remarks></remarks>
Protected _enumDesignLocked As GlobalLib.CommonData.enumEnableDisable = GlobalLib.CommonData.enumEnableDisable.Enabled
<CategoryAttribute("AA"), _
EditorBrowsable(EditorBrowsableState.Always), _
DesignerSerializationVisibility(DesignerSerializationVisibility.Visible), _
Browsable(True), _
[ReadOnly](False), _
BindableAttribute(False), _
DefaultValueAttribute(GetType(GlobalLib.CommonData.enumEnableDisable), "Disabled"), _
DesignOnly(False), _
DescriptionAttribute("")> _
Public Property DesignLocked() As GlobalLib.CommonData.enumEnableDisable
Get

Return Me._enumDesignLocked

End Get
Set(ByVal value As GlobalLib.CommonData.enumEnableDisable)

If value = GlobalLib.CommonData.enumEnableDisable.Enabled Then

' Sets ReadOnly
EnableProperty(Me, True, "PostPrintString")
'GlobalLib.Methods.EnableProperty(Me, True, "PostPrintString")

Else

' Clears ReadOnly
EnableProperty(Me, False, "PostPrintString")
'GlobalLib.Methods.EnableProperty(Me, False, "PostPrintString")

End If

Me._enumDesignLocked = value
Me._PropertyGrid.Refresh()

End Set
End Property

Public Sub EnableProperty(ByVal ctrl As Control, ByVal bState As Boolean, ByVal sPropName As String)
Dim descriptor As PropertyDescriptor = TypeDescriptor.GetProperties(ctrl.GetType())(sPropName)
If descriptor IsNot Nothing Then
Dim attr As ReadOnlyAttribute = descriptor.Attributes(GetType(ReadOnlyAttribute))
If attr IsNot Nothing Then
Dim field As FieldInfo = attr.GetType().GetField("isReadOnly", _
System.Reflection.BindingFlags.NonPublic Or _
System.Reflection.BindingFlags.Instance)
If field IsNot Nothing Then
field.SetValue(attr, bState)

'GlobalLib.DebugModule.DebugTextOut(String.Format("{0} - {1}", sPropName, attr.IsReadOnly()))
End If
End If
End If
End Sub

''' <summary>
''' Get/Set CustomTextBox.PostPrintString.
''' Defines text to be concatenated to the normal .Text when printing.
''' </summary>
''' <remarks></remarks>
<CategoryAttribute("AA"), _
EditorBrowsable(EditorBrowsableState.Always), _
DesignerSerializationVisibility(DesignerSerializationVisibility.Visible), _
Browsable(True), _
[ReadOnly](False), _
BindableAttribute(False), _
DefaultValueAttribute(""), _
DesignOnly(False), _
DescriptionAttribute("")> _
Public Property CtrlName() As String
Get
Return MyBase.Name
End Get
Set(ByVal value As String)
End Set
End Property

Private Sub TestUserControl_Paint(ByVal sender As System.Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles MyBase.Paint
e.Graphics.FillRectangle(Brushes.AliceBlue, Me.ClientRectangle)
e.Graphics.DrawString(Me.Name, Me.Font, Brushes.Black, 3, 3)
End Sub
End Class

-- modified 31-Jan-21 12:25pm.
QuestionInterfacing with Zlib.dll Pin
albert_redditt28-Jan-21 10:16
albert_redditt28-Jan-21 10:16 
AnswerRe: Interfacing with Zlib.dll Pin
20212a28-Jan-21 10:30
20212a28-Jan-21 10:30 
AnswerRe: Interfacing with Zlib.dll Pin
Richard MacCutchan28-Jan-21 21:14
mveRichard MacCutchan28-Jan-21 21:14 
QuestionUnable to complete the code for Web scrapping Pin
The Mentee27-Jan-21 8:56
The Mentee27-Jan-21 8:56 
AnswerRe: Unable to complete the code for Web scrapping Pin
Richard Deeming27-Jan-21 21:49
mveRichard Deeming27-Jan-21 21:49 
GeneralRe: Unable to complete the code for Web scrapping Pin
The Mentee28-Jan-21 0:06
The Mentee28-Jan-21 0:06 
GeneralRe: Unable to complete the code for Web scrapping Pin
DerekT-P28-Jan-21 7:07
professionalDerekT-P28-Jan-21 7:07 
GeneralPersonal Appointment Reminder Code Pin
mike Pant10-Jan-21 2:58
mike Pant10-Jan-21 2:58 
GeneralRe: Personal Appointment Reminder Code Pin
Victor Nijegorodov10-Jan-21 3:59
Victor Nijegorodov10-Jan-21 3:59 
GeneralRe: Personal Appointment Reminder Code Pin
Gerry Schmitz10-Jan-21 4:47
mveGerry Schmitz10-Jan-21 4:47 
QuestionExcel VBA Macro Pin
tutymano5-Jan-21 17:49
tutymano5-Jan-21 17:49 
AnswerRe: Excel VBA Macro Pin
Dave Kreskowiak5-Jan-21 19:55
mveDave Kreskowiak5-Jan-21 19:55 
AnswerRe: Excel VBA Macro Pin
Mycroft Holmes6-Jan-21 11:02
professionalMycroft Holmes6-Jan-21 11:02 
QuestionChange mac address by vba Pin
Member 1447788423-Dec-20 14:47
Member 1447788423-Dec-20 14:47 
AnswerRe: Change mac address by vba Pin
Dave Kreskowiak23-Dec-20 17:30
mveDave Kreskowiak23-Dec-20 17:30 
GeneralRe: Change mac address by vba Pin
Member 1447788423-Dec-20 18:35
Member 1447788423-Dec-20 18:35 
GeneralRe: Change mac address by vba Pin
Gerry Schmitz24-Dec-20 5:14
mveGerry Schmitz24-Dec-20 5:14 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.