ComboBoxes and the sorted property

G

Guest

Discovered a fun one that I thought I should share, and hopefully catch
Microsoft's attention to update some documentation.

I'm a bit new to VB.NET, and was struggling with getting a combo box to
work. I was attempting to take advantage of the cool way to load a combo box
via a datasource, rather than the old VB6 way of adding selections.

First I tried an array of objects. I had some issues with that that I
suspect had a lot to do with not overloading ToString on the class so the
combo box would return the right thing for the displaymember item. But I had
also read some bugs around arrays and combo boxes, so I switched to a
disconnected dataset.

I had a heck of a time getting the combo box to load properly. I kept
getting either no data in the combo box, or it kept showing the phrase
"System.Data.DataRowView". I found out that you have to set the datasource
property first, before you set the datamember and the valuemember properties.

But the real kicker was that you can't use the datasource and get it to work
if the sorted property on the combo box is set to true. It appears that if
you set that property to true, then the combo box assumes you're going to do
things the old VB6 way and use the Add items method to the combo box. My
tipoff something was wrong that I'd watch the debugger, and right after the
statement like this:

cbTest.DataSource = dsInfo.Tables(0)

the value of cbTest.Datasource was "nothing", like the assignment didnt take.

In order to get things to work the way I wanted them to, I simply built a
dataview that sorted the table for me, and fed that to the combobox with the
sorted value off, and it finally worked. Three weeks later, of course.

Would someone from Microsoft confirm that you shouldn't use datasource in
combo and list boxes if you set the Sorted property to true in the form
designer? If that is the case, note that somewhere in the MSDN information
about the ListBox and the ComboBox classes!! It's not mentioned in the
MSPress books either (I have Programming Microsoft Visual Basic.Net, the 2003
version, ISBN 0-7356-2059-8)
 
G

Guest

Wow! Thanks for this posting.
I am migrating a windows app from v1.0 to v1.1 and ran across this problem
which obviously did not exist with v1.0. Thanks again...Troy
 
G

Guest

This bug is an embarassment to Microsoft and should be addressed in the next
version. I just wasted 2 hours trying to get a DataTable to bind to a combo
box and luckily ran across this post. Turns out that if you create a
strongly typed DataSet using the Component class container and use the
DataTable that resides inside, you do not have to use the DataView on the
DataTable. Insconsistent and frustrating!!

Bret
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top