By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,275 Members | 1,311 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,275 IT Pros & Developers. It's quick & easy.

weird problem with filling comboboxes using DataSource/DisplayMemb

P: n/a
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 =
ergoDB._ProjectsDS.Tables["Projekte"];
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
System.Data.DataRowView.
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
ones:

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:
System.Data.DataViewManagerListItemTypeDescriptor
?!?!?!?!?!?

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
Share this Question
Share on Google+
1 Reply


P: n/a
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.