View Single Post
  #10 (permalink)  
Old May 12th, 2004, 07:12 AM
Ron Howerton Ron Howerton is offline
Friend of Wrox
Points: 2,702, Level: 21
Points: 2,702, Level: 21 Points: 2,702, Level: 21 Points: 2,702, Level: 21
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Denver, CO, USA.
Posts: 425
Thanks: 57
Thanked 2 Times in 2 Posts
Default

The Combobox was bound to the dataset in pretty much the same way as you show in code, except done in the VS GUI Properties window. The dataset was created from an adapter dropped on the form from the server explorer for the table. The DisplayMember and ValueMember of the combobox were then bound to their respective fields, also in the VS GUI. I was then sharing that dataset with another table being bound to another combobox. Somehow this appeared to result in the combobox thinking it was bound to a datarowview instead of individual fields.

I tried different combinations of binding for the combobox to see if I screwed something up there. One way you bind the DataSource to the dataset only, and then reference both table and fieldname in the DisplayMember and ValueMember properites. Another way is to bind the source to the dataset and table, and then DM and VM properties to just the fields within the table. Niether way seemed to to work, though.

Using katsarosj's suggestion with a slight modification, I discovered I was able reference the DisplayMember field explicitly, as though looking at a datarow, so VB was certainly right in that respect. But I then couldn't reference the SelectedIndex which made that solution unusable for my purpose. But it was enough to show that VB was technically correct in the error being returned, although it was of no use in understanding or correcting the problem being encountered. I'd say your suggestion is a fairly simple solution - I just wish it was easier to find. In any case, it wouldn't work either until I simplified the dataset structure by including only the table bound to the combobox. It's a part of my collection of .NET tricks now, though. Thanks!
Reply With Quote