ComboBox bound to enum value not holding selected index


Author
Message
Andria Jensen
Andria Jensen
StrataFrame User (444 reputation)StrataFrame User (444 reputation)StrataFrame User (444 reputation)StrataFrame User (444 reputation)StrataFrame User (444 reputation)StrataFrame User (444 reputation)StrataFrame User (444 reputation)StrataFrame User (444 reputation)StrataFrame User (444 reputation)
Group: Forum Members
Posts: 336, Visits: 497
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?
Andria Jensen
Andria Jensen
StrataFrame User (444 reputation)StrataFrame User (444 reputation)StrataFrame User (444 reputation)StrataFrame User (444 reputation)StrataFrame User (444 reputation)StrataFrame User (444 reputation)StrataFrame User (444 reputation)StrataFrame User (444 reputation)StrataFrame User (444 reputation)
Group: Forum Members
Posts: 336, Visits: 497
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.
Trent Taylor
Trent Taylor
StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)
Group: StrataFrame Developers
Posts: 6.6K, Visits: 6.9K
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.
Andria Jensen
Andria Jensen
StrataFrame User (444 reputation)StrataFrame User (444 reputation)StrataFrame User (444 reputation)StrataFrame User (444 reputation)StrataFrame User (444 reputation)StrataFrame User (444 reputation)StrataFrame User (444 reputation)StrataFrame User (444 reputation)StrataFrame User (444 reputation)
Group: Forum Members
Posts: 336, Visits: 497
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.
Trent Taylor
Trent Taylor
StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)
Group: StrataFrame Developers
Posts: 6.6K, Visits: 6.9K
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

Andria Jensen
Andria Jensen
StrataFrame User (444 reputation)StrataFrame User (444 reputation)StrataFrame User (444 reputation)StrataFrame User (444 reputation)StrataFrame User (444 reputation)StrataFrame User (444 reputation)StrataFrame User (444 reputation)StrataFrame User (444 reputation)StrataFrame User (444 reputation)
Group: Forum Members
Posts: 336, Visits: 497
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). 
Andria Jensen
Andria Jensen
StrataFrame User (444 reputation)StrataFrame User (444 reputation)StrataFrame User (444 reputation)StrataFrame User (444 reputation)StrataFrame User (444 reputation)StrataFrame User (444 reputation)StrataFrame User (444 reputation)StrataFrame User (444 reputation)StrataFrame User (444 reputation)
Group: Forum Members
Posts: 336, Visits: 497
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.
Attachments
ComboBinding.bmp (97 views, 2.00 MB)
Trent Taylor
Trent Taylor
StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)
Group: StrataFrame Developers
Posts: 6.6K, Visits: 6.9K
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.

Attachments
WindowsApplication11.zip (89 views, 715.00 KB)
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