-
Mar 20th, 2015, 05:33 AM
#1
[RESOLVED] Custom property binding not working???
I have created a property in a control that inherits ComboBox:
vb Code:
<System.ComponentModel.Bindable(True)>
<System.ComponentModel.DesignerSerializationVisibility(System.ComponentModel.DesignerSerializationVisibility.Hidden)>
Public Property EnumValue As Integer
Get
Dim EnumAttribute = TryCast(Me.SelectedItem, EnumAttribute)
If EnumAttribute Is Nothing Then
Return Nothing
Else
Return Convert.ToInt32(EnumAttribute.Enum)
End If
End Get
Set(value As Integer)
Dim ListItem = Me.Items.OfType(Of EnumAttribute)().Where(Function(x) Convert.ToInt32(x.Enum) = value).FirstOrDefault
If ListItem IsNot Nothing Then
Me.SelectedItem = ListItem
End If
End Set
End Property
Private Sub DataEnumDropdown_SelectedValueChanged(sender As Object, e As EventArgs) Handles Me.SelectedValueChanged
RaiseEvent PropertyChanged(Me, New System.ComponentModel.PropertyChangedEventArgs("EnumValue"))
End Sub
I have setup a custom binding like:
vb Code:
cboServerType.DataBindings.Clear()
cboServerType.DataBindings.Add("EnumValue", value, "ServerType", False, DataSourceUpdateMode.OnPropertyChanged)
It is a value list and my issue is when the combo box value gets changed the PropertyChanged event gets fired but the underlying item doesn't update (in this case the ServerType property)...
Any ideas where I am going wrong?
Thanks,
Kris
-
Mar 20th, 2015, 10:36 AM
#2
Addicted Member
Re: Custom property binding not working???
The way you have the DataBinding set up, the object value.ServerType PropertyChangedEvent should update the Property "EnumValue". Possibly you have it wired backwards.
-
Mar 20th, 2015, 04:26 PM
#3
Re: Custom property binding not working???
Originally Posted by OICU812
The way you have the DataBinding set up, the object value.ServerType PropertyChangedEvent should update the Property "EnumValue". Possibly you have it wired backwards.
The binding should work both ways... but I really only care about the control updating the underlying item in this case...
It works for everything else on the form ... like textboxes, checkboxes etc ... just not for my custom combobox ...
EDIT: I should probably say the exact symptoms ... when I change the selected inherited combo box item the underlying item doesn't update, but the combo lets it change ... when my combo box looses focus it resets it to the value that it is bound to?
Any other ideas?
Thanks,
Kris
Last edited by i00; Mar 20th, 2015 at 05:05 PM.
-
Mar 20th, 2015, 10:15 PM
#4
Re: Custom property binding not working???
When the SelectedValueChanged event fires, I see that it raises the property changed event identifying EnumValue... but I don't see the underlying value being changed...
Maybe I'm missing something.
-tg
-
Mar 21st, 2015, 02:30 AM
#5
Re: Custom property binding not working???
Originally Posted by techgnome
When the SelectedValueChanged event fires, I see that it raises the property changed event identifying EnumValue... but I don't see the underlying value being changed...
Maybe I'm missing something.
-tg
The binding is supposed to change the underlying property:
vb Code:
cboServerType.DataBindings.Add("EnumValue", value, "ServerType", False, DataSourceUpdateMode.OnPropertyChanged)
Doing this is supposed to watch the PropertyChanged for the change and update the underlying data source automatically... It works for all of the built in control properties... I need it to work for my one too!
Kris
-
Mar 21st, 2015, 11:44 AM
#6
Re: Custom property binding not working???
is the binding working in the other direction? this is: if you set "value.ServerType" to some value that is in the combo and then bind it, does the combo display the matching text?
-
Mar 21st, 2015, 05:02 PM
#7
Re: Custom property binding not working???
Originally Posted by digitalShaman
is the binding working in the other direction? this is: if you set "value.ServerType" to some value that is in the combo and then bind it, does the combo display the matching text?
Yes changing the underlying item updates the combobox.. but I really want it to work both ways ... so when the user changes the value in my combo box it automatically updates the underlying item.
Kris
-
Mar 21st, 2015, 05:23 PM
#8
Re: Custom property binding not working???
maybe silly, but have you checked that the EnumValue getter actually returns a value when you have select the value you want?
-
Mar 21st, 2015, 05:26 PM
#9
Re: Custom property binding not working???
Ok... worked it out ... you cannot bind a enum to an int ... so I created another property that reflects the enum value in an integer
Kris
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|