﻿<?xml version="1.0" encoding="UTF-8"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/"><channel><title>StrataFrame Forum » StrataFrame Application Framework - V1 » WinForms (How do I?)  » Combo bound to enum not holding value correctly</title><generator>InstantForum 2017-1 Final</generator><description>StrataFrame Forum</description><link>http://forum.strataframe.net/</link><webMaster>StrataFrame Forum</webMaster><lastBuildDate>Mon, 08 Jun 2026 18:25:09 GMT</lastBuildDate><ttl>20</ttl><item><title>Combo bound to enum not holding value correctly</title><link>http://forum.strataframe.net/FindPost12867.aspx</link><description>I have a combo that is populated at runtime with string values and must be done this way due to multilingual issues.&amp;nbsp; It has a BindingField set to a field which is customized as an enum value, and the BindingProperty set to SelectedIndex.&amp;nbsp; I figured that this would work since an enum should cast to an integer which would be correct for setting the SelectedIndex property.&amp;nbsp; What I'm seeing at runtime&amp;nbsp;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.&amp;nbsp; So basically, I can't change the value from whatever the original is.&amp;nbsp; Any reason you know of&amp;nbsp;this is happening, and anything I can do to fix it?</description><pubDate>Mon, 03 Dec 2007 10:01:33 GMT</pubDate><dc:creator>Andria Jensen</dc:creator></item><item><title>RE: Combo bound to enum not holding value correctly</title><link>http://forum.strataframe.net/FindPost12893.aspx</link><description>OK, i may try it that way.&amp;nbsp; Thanks for the help!&amp;nbsp; This one's been driving me up the wall lately.&amp;nbsp; :w00t:</description><pubDate>Mon, 03 Dec 2007 10:01:33 GMT</pubDate><dc:creator>Andria Jensen</dc:creator></item><item><title>RE: Combo bound to enum not holding value correctly</title><link>http://forum.strataframe.net/FindPost12891.aspx</link><description>Yes, you would have to inherit one for each enum.&amp;nbsp; But, you could also create a generic class so you don't have to duplicate the code every time.&lt;/P&gt;&lt;P&gt;SF.DevExpress.CombEdit -&amp;gt; GenericEnumComboEdit -&amp;gt; SpecificEnumComboEdit&lt;/P&gt;&lt;P&gt;The definition of the GenericEnumComboEdit would be like this:&lt;/P&gt;&lt;P&gt;Public Class GenericEnumComboEdit(Of TEnum)&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Inherits ComboEdit&lt;/P&gt;&lt;P&gt;Everywhere in the code sample before where you have MyEnum, you would replace it with TEnum.&lt;/P&gt;&lt;P&gt;Then, you could have one code file for all of your specific enum combo boxes, because it would only take 3 lines of code for each:&lt;/P&gt;&lt;P&gt;Public Class MyEnumComboEdit&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Inherits GenericEnumComboEdit(Of MyEnum)&lt;BR&gt;End Class&lt;/P&gt;&lt;P&gt;Public Class MyEnum2ComboEdit&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Inherits GenericEnumComboEdit(Of MyEnum2)&lt;BR&gt;End Class&lt;/P&gt;&lt;P&gt;So, it wouldn't require that much code to do it that way if you wanted to.</description><pubDate>Mon, 03 Dec 2007 09:56:01 GMT</pubDate><dc:creator>StrataFrame Team</dc:creator></item><item><title>RE: Combo bound to enum not holding value correctly</title><link>http://forum.strataframe.net/FindPost12890.aspx</link><description>So would I have to inherit one for every different enum value then??&amp;nbsp; Sounds like it would be easier to just have it come back as an integer and cast it when necessary.</description><pubDate>Mon, 03 Dec 2007 09:44:56 GMT</pubDate><dc:creator>Andria Jensen</dc:creator></item><item><title>RE: Combo bound to enum not holding value correctly</title><link>http://forum.strataframe.net/FindPost12882.aspx</link><description>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).&amp;nbsp; 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).&amp;nbsp; 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.&amp;nbsp; Like this:&lt;/P&gt;&lt;P&gt;Public Property SelectedIndexEnum() As MyEnum&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Get&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Return CType(Me.SelectedIndex, MyEnum)&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; End Get&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Set(ByVal value As MyEnum)&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Me.SelectedIndex = CType(value, Integer)&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; End Set&lt;BR&gt;End Property&lt;/P&gt;&lt;P&gt;And you'll also need to create an event for change notification for the binding or all is for nothing ;)&lt;BR&gt;&lt;BR&gt;Public Event SelectedIndexEnumChanged As EventHandler&lt;BR&gt;&lt;BR&gt;Protected Overrides Sub SelectedIndexChanged(ByVal e As EventArgs)&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; '-- Raise the SelectedIndexChanged event&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; MyBase.OnSelectedIndexChanged(e)&lt;BR&gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; '-- Raise your event right after it&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; RaiseEvent SelectedIndexEnumChanged(Me, e)&lt;BR&gt;End Sub&lt;/P&gt;&lt;P&gt;So, any time the selected index changes, your custom event "changes," too, so the binding can update the value.</description><pubDate>Mon, 03 Dec 2007 08:45:08 GMT</pubDate><dc:creator>StrataFrame Team</dc:creator></item><item><title>RE: Combo bound to enum not holding value correctly</title><link>http://forum.strataframe.net/FindPost12868.aspx</link><description>Just a bit more detail here...this is an inherited DevEx combo.&amp;nbsp; 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.&amp;nbsp; I only get the&amp;nbsp;problem when I have an enum in the BOM customization for the BindingField.&amp;nbsp;&lt;/P&gt;&lt;P&gt;I know I have posted this before but I never got a fix for it.&amp;nbsp; I ended up just not using enums in the BOM anymore.&amp;nbsp; I really would like to resolve this so I can use them without errors like this cropping up.&amp;nbsp; Thanks for the help.</description><pubDate>Thu, 29 Nov 2007 10:42:45 GMT</pubDate><dc:creator>Andria Jensen</dc:creator></item></channel></rss>