StrataFrame Forum

ComboBox bound to enum value not holding selected index

http://forum.strataframe.net/Topic10866.aspx

By Andria Jensen - 8/14/2007

I have a combo box which is populated at runtime with string values (not from an enum).  It is then bound to an enum value which is the selected index of the combo.  I'm seeing some weird behavior in that I can select an item from the dropdown, but immediately when it loses focus the index returns back to the previously selected item.  It's just like the value i'm selecting isn't "sticking" after the combo loses focus.  I am not handling any events that I can see which are modifying this value at all.  The only thing I could figure is that it's something weird with how I setup the enum since I just changed this to be an enum in the mapper instead of an int.  I thought I did it correctly, but perhaps I could have missed a step somewhere?
By Andria Jensen - 8/14/2007

Oh, I should also mention that this is a DevExpress inherited combo.  Not sure if there's something unique about how those handles binding to an enum value.
By Trent L. Taylor - 8/15/2007

Well, you mentioned that you are manually populating the combo.  Have you changed the BindingProperty to Text or whatever value it should actually be binding to.  By default the combos will bind to the Selectedvalue property, so if you are just using this combo to bind to text, you will want to change the BindingProperty to Text or something of that nature instead.
By Andria Jensen - 8/15/2007

The BindingProperty is set to SelectedIndex.  It works just fine if the BO Mapper is set to return that field as an Int16.  It's only when I map it as an enum that I get the behavior I mentioned.  As far as setting the BindingProperty to text...I'm not sure how that would work since the enum corresponds to the combo index, not the text.  Please let me know if I'm just completely misunderstanding something here.
By Trent L. Taylor - 8/15/2007

I had just misunderstood your previous post.  I thought you were trying to bind to the text.  I understand what you are trying to so.  The DevExpress combo acts slightly different than other combos so I always have to tinker with them when I want to get them to work in a situation like this.  It their SelectedIndex property is Int16 that could be the problem.  I don't know if it is or not and would have to look into it deeper to know.  If you manually populate the combo (do not use a enum) does the problem persist?  For example, just create an ADO.NET DataTable and tie it to the combo.

Dim loTable As New DataTable()
'-- Create your columns
loTable.Columns.Add("desc",GetType(System.String))
loTable.Columns.Add("value",GetType(System.Integer))
'-- Add your rows manually here
'-- Attach the data source to the combo
MyCombo.DisplayMember = "desc"
MyCombo.ValueMember = "value"
MyCOmbo.DataSource = loTable
By Andria Jensen - 8/15/2007

Actually, I am already populating the combo manually.  I have no problems populating the combo.  We use a multilingual database and have to populate all combos from it.  The only issue is that the BindingField value that is coming out of the BO is not hooking up to the SelectedIndex BindingProperty correctly (or at least that's what it seems like). 
By Andria Jensen - 8/15/2007

Just to clarify, I am attaching a screenshot of the properties for my combo box.  Also, the combo is populating using simple Items.Add calls and passing in the text from the multilingual db.  It is does not have a data source set.
By Trent L. Taylor - 8/16/2007

Andrea,

I created a sample database and a sample application and it worked without issue.  Attached is the sample I created.  You can use the DatabaseInstaller sample to deploy the package file (or bring it into a new DDT profile). In either case, if you deploy this first, then open the AppMain and change the connection string to match your server.  Run the sample and it should work.  It worked fine for me.  Let me know if you have any issues.  Thanks.