Combo bound to enum not holding value correctly


Author
Message
Andria Jensen
Andria Jensen
Advanced StrataFrame User (600 reputation)Advanced StrataFrame User (600 reputation)Advanced StrataFrame User (600 reputation)Advanced StrataFrame User (600 reputation)Advanced StrataFrame User (600 reputation)Advanced StrataFrame User (600 reputation)Advanced StrataFrame User (600 reputation)Advanced StrataFrame User (600 reputation)Advanced StrataFrame User (600 reputation)
Group: Forum Members
Posts: 336, Visits: 497
I have a combo that is populated at runtime with string values and must be done this way due to multilingual issues.  It has a BindingField set to a field which is customized as an enum value, and the BindingProperty set to SelectedIndex.  I figured that this would work since an enum should cast to an integer which would be correct for setting the SelectedIndex property.  What I'm seeing at runtime is that I can change the value in the combobox all I want, but as soon as it loses focuses it goes back to the original value that it was bound to.  So basically, I can't change the value from whatever the original is.  Any reason you know of this is happening, and anything I can do to fix it?
Replies
Andria Jensen
Andria Jensen
Advanced StrataFrame User (600 reputation)Advanced StrataFrame User (600 reputation)Advanced StrataFrame User (600 reputation)Advanced StrataFrame User (600 reputation)Advanced StrataFrame User (600 reputation)Advanced StrataFrame User (600 reputation)Advanced StrataFrame User (600 reputation)Advanced StrataFrame User (600 reputation)Advanced StrataFrame User (600 reputation)
Group: Forum Members
Posts: 336, Visits: 497
Just a bit more detail here...this is an inherited DevEx combo.  Also, I can clear the customization in the BOM so that it is just giving me back an integer instead of an enum and it works as expected.  I only get the problem when I have an enum in the BOM customization for the BindingField. 

I know I have posted this before but I never got a fix for it.  I ended up just not using enums in the BOM anymore.  I really would like to resolve this so I can use them without errors like this cropping up.  Thanks for the help.

StrataFrame Team
S
StrataFrame Developer (6.5K reputation)StrataFrame Developer (6.5K reputation)StrataFrame Developer (6.5K reputation)StrataFrame Developer (6.5K reputation)StrataFrame Developer (6.5K reputation)StrataFrame Developer (6.5K reputation)StrataFrame Developer (6.5K reputation)StrataFrame Developer (6.5K reputation)StrataFrame Developer (6.5K reputation)
Group: StrataFrame Developers
Posts: 3K, Visits: 2.5K
The problem has to do with the way .NET binding works... if the .NET binding formatting cannot convert the value between the two types, the value is just not copied back to the data source, so, for some reason, .NET cannot convert between the enum and the integer value of the bound property on the combo (maybe because it requires and explicit cast, I dunno).  But we've noticed the same thing... if you have a strong-typed property mapped as an enum, you have to bind to a value on the combo box that is an enum (such as when you use the enum population options of the combo box).  So, if you want to keep your SelectedIndex binding and use an enum, you'll need to inherit the SF DevExpress ComboEdit (or whatever control you're using) and create a custom property that returns an enum for binding.  Like this:

Public Property SelectedIndexEnum() As MyEnum
    Get
        Return CType(Me.SelectedIndex, MyEnum)
    End Get
    Set(ByVal value As MyEnum)
        Me.SelectedIndex = CType(value, Integer)
    End Set
End Property

And you'll also need to create an event for change notification for the binding or all is for nothing Wink

Public Event SelectedIndexEnumChanged As EventHandler

Protected Overrides Sub SelectedIndexChanged(ByVal e As EventArgs)
    '-- Raise the SelectedIndexChanged event
    MyBase.OnSelectedIndexChanged(e)

    '-- Raise your event right after it
    RaiseEvent SelectedIndexEnumChanged(Me, e)
End Sub

So, any time the selected index changes, your custom event "changes," too, so the binding can update the value.

GO

Merge Selected

Merge into selected topic...



Merge into merge target...



Merge into a specific topic ID...





Similar Topics

Reading This Topic

Login

Explore
Messages
Mentions
Search