Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

Given a combobox (cbClient dropdown) - the user can select one of the items listed in the combobox and when he does I need to know what item he selected. The combobox is populated by a DataSet (as shown in the code below), everytime I try to get the value of the selected item I get "System.Data.DataRowView" instead ???

 

System.Data.DataSet ds = new System.Data.DataSet();
ds = Database.Read("select * from [TaskTimer$]");

cbClient.SelectedIndex = -1;
cbClient.DataSource = ds.Tables[0];
cbClient.DisplayMember = "CLIENTS";
cbClient.ValueMember = "CLIENTS";
...
... The user can do stuff like select a Client from the ComboBox DropDown
...
string sSelectedClient = cbClient.SelectedItem.ToString();

 

So I am trying to get sSelectedClient to be = the selected client from the DrownDown Combobox.... but thats not what I am getting.

Do I need to CAST it somehow, into like a DATASET and then extract it as such? If so how would I go about doing that?

Any help/hints would be greatly appreciated

Posted
string sSelectedClient = cbClient.text

 

Although this is perfectly valid, it can cause more problems if, for example, the DropDownStyle is 'DropDown' and not 'DropDownList'

 

This will allow the end user to type in "anything" they want in the combobox, and the above code will simply return what they typed, not what was selected.

 

Of course, if the DropDownStyle *is* DropDownList, then the above code will have the same effect as the code I posted.

 

B.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...