Shaitan00 Posted March 26, 2005 Posted March 26, 2005 --Using [VS C#.NET]-- Given a ComboBox [cb] that is populated by a dataset [ds from an SQL query] using the .DataSource method. cbJob.DataSource = ds.Tables[0]; cbJob.DisplayMember = "ID"; Want I need to do later on is get the ID (integer) value selected by the Combobox. However everytime I try I keep getting back a DataRowView (if I do cb.SelectedItem). Correct me if I am wrong but I assume the solution is to cast the .SelectedItem as a DataRow (or something) and then access the [iD] field? I have tried a few times and can't seem to get it to work, any ideas/help? Thanks Quote
barski Posted March 27, 2005 Posted March 27, 2005 the easy way would be to use the selectedvalue instead of item. If you need access to field other than id then DataRow dR = (DataRow)cmb.SelectedItem string otherfield = dR["otherfield"].ToString(); 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.