Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

--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

Posted

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();

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...