Results 1 to 9 of 9

Thread: [RESOLVED] Custom property binding not working???

  1. #1

    Thread Starter
    PowerPoster i00's Avatar
    Join Date
    Mar 2002
    Location
    1/2 way accross the galaxy.. and then some
    Posts
    2,388

    Resolved [RESOLVED] Custom property binding not working???

    I have created a property in a control that inherits ComboBox:

    vb Code:
    1. <System.ComponentModel.Bindable(True)>
    2.     <System.ComponentModel.DesignerSerializationVisibility(System.ComponentModel.DesignerSerializationVisibility.Hidden)>
    3.     Public Property EnumValue As Integer
    4.         Get
    5.             Dim EnumAttribute = TryCast(Me.SelectedItem, EnumAttribute)
    6.             If EnumAttribute Is Nothing Then
    7.                 Return Nothing
    8.             Else
    9.                 Return Convert.ToInt32(EnumAttribute.Enum)
    10.             End If
    11.         End Get
    12.         Set(value As Integer)
    13.             Dim ListItem = Me.Items.OfType(Of EnumAttribute)().Where(Function(x) Convert.ToInt32(x.Enum) = value).FirstOrDefault
    14.             If ListItem IsNot Nothing Then
    15.                 Me.SelectedItem = ListItem
    16.             End If
    17.         End Set
    18.     End Property
    19.  
    20.     Private Sub DataEnumDropdown_SelectedValueChanged(sender As Object, e As EventArgs) Handles Me.SelectedValueChanged
    21.         RaiseEvent PropertyChanged(Me, New System.ComponentModel.PropertyChangedEventArgs("EnumValue"))
    22.     End Sub

    I have setup a custom binding like:

    vb Code:
    1. cboServerType.DataBindings.Clear()
    2. 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

  2. #2
    Addicted Member
    Join Date
    Oct 2012
    Location
    Springfield, IL
    Posts
    142

    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.

  3. #3

    Thread Starter
    PowerPoster i00's Avatar
    Join Date
    Mar 2002
    Location
    1/2 way accross the galaxy.. and then some
    Posts
    2,388

    Re: Custom property binding not working???

    Quote Originally Posted by OICU812 View Post
    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

  4. #4
    Smooth Moperator techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,532

    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
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  5. #5

    Thread Starter
    PowerPoster i00's Avatar
    Join Date
    Mar 2002
    Location
    1/2 way accross the galaxy.. and then some
    Posts
    2,388

    Re: Custom property binding not working???

    Quote Originally Posted by techgnome View Post
    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:
    1. 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

  6. #6
    Frenzied Member
    Join Date
    May 2014
    Location
    Central Europe
    Posts
    1,372

    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?

  7. #7

    Thread Starter
    PowerPoster i00's Avatar
    Join Date
    Mar 2002
    Location
    1/2 way accross the galaxy.. and then some
    Posts
    2,388

    Re: Custom property binding not working???

    Quote Originally Posted by digitalShaman View Post
    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

  8. #8
    Frenzied Member
    Join Date
    May 2014
    Location
    Central Europe
    Posts
    1,372

    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?

  9. #9

    Thread Starter
    PowerPoster i00's Avatar
    Join Date
    Mar 2002
    Location
    1/2 way accross the galaxy.. and then some
    Posts
    2,388

    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
  •  



Click Here to Expand Forum to Full Width