Combo Box Problem

  • Thread starter Thread starter Sudhir Sharma via .NET 247
  • Start date Start date
S

Sudhir Sharma via .NET 247

Hi Guys,
I Have some strange problem while adding items to the Combo Box.it shows "System.Data.DataRow" as diplay Memeber. I am gettingdata into a DataTable from Database through query "SeelctSource,SourceID from SourceTable" and setting Valuemember as"SourceID" and Display member as "Source" of combobox throughVB.NET Designer.
then I am adding data to Combo box through a loop for thatDatatbale because I have to add a Blank row first ..like..

combobox.items.add("")
for i=0 to dt.rows.count-1
ComboBox.items.add(dt.rows(i))
Next

after that. I see three rows in ComboBox with display member as"System.Data.DataRow"
Any help appreciated.
Thanks in Advance
Sudhir
 
I think if you kill that first line you should be good to go. I dont' think
it will be able to determine the DisplayMember and Valuemember if that field
is in it.

You may also just want to do the old
combobox1.DataSource = dt;
combobox1.DisplayMember = "Source";
combobox1.ValueMember = "SourceID":

--
W.G. Ryan MVP Windows - Embedded

Have an opinion on the effectiveness of Microsoft Embedded newsgroups?
Let Microsoft know!
https://www.windowsembeddedeval.com/community/newsgroups
Hi Guys,
I Have some strange problem while adding items to the Combo Box. it shows
"System.Data.DataRow" as diplay Memeber. I am getting data into a DataTable
from Database through query "Seelct Source,SourceID from SourceTable" and
setting Valuemember as "SourceID" and Display member as "Source" of combobox
through VB.NET Designer.
then I am adding data to Combo box through a loop for that Datatbale because
I have to add a Blank row first ..like..

combobox.items.add("")
for i=0 to dt.rows.count-1
ComboBox.items.add(dt.rows(i))
Next

after that. I see three rows in ComboBox with display member as
"System.Data.DataRow"
Any help appreciated.
Thanks in Advance
Sudhir
 
Hi Sudhir,

combobox.items.add("")
for i=0 to dt.rows.count-1
ComboBox.items.add(dt.rows(i))
Next

It is strange that you succeed in this.

The most made mistake when using the designer and getting the results as
yours is that you have set the datasource in the designer to the dataset and
not to the table. You have to push on the + for that and than select the
table that has to be used.

And that code above you can(should be) remove.

I hope this helps?

Cor
 
i have the same problem before, now i deal it in this way:

1. getting data into a DataTable
2. insert a blank row at the top of DataTable
3. bind the comboxBox with the DataTable

combobox1.DataSource = dt;
combobox1.DisplayMember = "Source";
combobox1.ValueMember = "SourceID":

Hi Guys,
I Have some strange problem while adding items to the Combo Box. it shows
"System.Data.DataRow" as diplay Memeber. I am getting data into a DataTable
from Database through query "Seelct Source,SourceID from SourceTable" and
setting Valuemember as "SourceID" and Display member as "Source" of combobox
through VB.NET Designer.
then I am adding data to Combo box through a loop for that Datatbale because
I have to add a Blank row first ..like..

combobox.items.add("")
for i=0 to dt.rows.count-1
ComboBox.items.add(dt.rows(i))
Next

after that. I see three rows in ComboBox with display member as
"System.Data.DataRow"
Any help appreciated.
Thanks in Advance
Sudhir
 
Hi Chen.

I think that is when it displays in the textbox the .......once.
That you can normaly correct with

combobox.selectedindex = -1
combobox.selectedindex = -1
(Twice because that is a bug)

Maybe that works for you as well?

Cor
 
Here's the definitive answer (took me days to figure this out).

1. To clear a bound combo you must use:
cbo.SelectedIndex = -1
cbo.SelectedIndex = -1
-- yes, use the same line twice (this is a MS confirmed bug 327244)

2. To have your combo cleared INITIALLY when the form loads assign it to a new BindingContext before binding in the Load event. This works with MDI & Tabs as well:

Form_Load()
Dim bc as New BindingContext
cbo.BindingContext = bc
..bind cbo here
cbo.cbo.SelectedIndex = -1 'this works fine now

3. Use both methods in the project to get the expected behavior.
 
Back
Top