471,594 Members | 2,062 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,594 software developers and data experts.

weird problem with filling comboboxes using DataSource/DisplayMemb

Hello everyone!

I have some weird(?) problems, and I am not quite sure if there are due to
my errors or maybe a limitation in the .Net framework.

I have a ComboBox I need to fill with the content of an untyped DataSet.
This is to be done in the "DropDown" Event (since the dataset is empty at
program start).

If I go with this:

this.cmbBx_SelectProjekte.DataSource =
this.cmbBx_SelectProjekte.DisplayMember = "BV_Name";

and the "Sorted" Property set to true, the comboBox remains empty !?!?
If I change the "Sorted" property to false, it works, I get the content from
the DataSet.

But with three big problems:
First of all, in that instance that I open the dropdown section of the
comboBox, the first Item is selected. This must not happen, since a lot of
code gets executed in the "SelectedItemChanged" Event, which should only be
executed if the USER selected an item.
The second problem is, that the SelectedItems are typeof
Why? The content of my DataSet consists of strings, which I do get if I use
a for-loop to fill the ComboBox.
Even worse, before the first string from the dataset finally arrives in the
box, there are two System.Data.DataRow Strings(!!) getting written into the
ComboBox that I need to filter?!?!?

But the worst problem of all is, that I do need the content SORTED.

Now, one other solutions erases some of my problems, but creates weird new

If I fill my comboBox with this:

for(int i=0; i<ergoDB._ProjectsDS.Tables["Projekte"].Rows.Count; i++)
this.cmbBx_SelectProjekte.Items.Add(ergoDB._Projec tsDS.Tables["Projekte"].Rows[i].ItemArray[1]);

and "Sorted" = true, its all fine. I got the drowDown Section filled, no
item is selected until I do so explicitly and the items in the array are
typeof string.
So far so good, I should be happy here. Should I?

If I set Sorted to false, the comboBox gets filled with the following string:

Now here's why I can't go for the loop and Sorted = true:
In the end, the strings that fill the combobox need to consists of two
columns of my dataset (projectnumber and projectname appended).
Heres the catch: If an item is selected, I do need the ValueMember property,
since I must process the projectnumber differently from the rest.
So I can't go with the loop, which is the only one that so far fully works.

What the hell is going on here?
This is driving me crazy, I have so much other stuff to take care off...
Please, I need help quite desperatly...

Jul 21 '05 #1
1 1955
To make it more clearly:

What I need in the end is:
* The comboBox filled with a sorted list.
* each item is a combination of two columns (projectNumber + projectName)
* the text-field of the comboBox empty as long as no item of the list has
been selected explicitly
* the ValueMember filled with the content of the projectnumber column

And the following needs to be inserted:
Before the for loop I set the DataSource to the DataSet (but not the column):
this.cmbBx_SelectProjekte.DataSource = ergoDB._ProjectsDS;
without this, the loop doesn't work...

Jul 21 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by Timothy White | last post: by
1 post views Thread by Keith Henderson | last post: by
reply views Thread by XIAOLAOHU | last post: by
reply views Thread by leo001 | last post: by
reply views Thread by Anwar ali | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.