Shaitan00 Posted August 31, 2005 Posted August 31, 2005 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 Quote
penfold69 Posted August 31, 2005 Posted August 31, 2005 (edited) string sSelectedClient = ((DataRowView)cbClient.SelectedItem).Row("CLIENTS") Edited August 31, 2005 by penfold69 Quote
techmanbd Posted August 31, 2005 Posted August 31, 2005 string sSelectedClient = cbClient.text Quote Live as if you were to die tomorrow. Learn as if you were to live forever. Gandhi
penfold69 Posted August 31, 2005 Posted August 31, 2005 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. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.