Sign in to follow this  

[.net] ComboBox.ValueMember/SelectedValue - Solved

Recommended Posts

Hey guys, I've populated a ComboBox control via an XML-generated DataSet. I've got two columns that are used, CourseID and CourseName. I want to use the CourseID as the ValueMember so that it's returned from SelectedValue and CourseName for the text to display as the choices on the dropdown list. It all works fine except that SelectedValue seems to be returning SelectedIndex + 1, and not the CourseIDs as intended. Here's the code setting up the ComboBox:
this.cmbCourse.DataSource = this.registerDataSet.Course;
this.cmbCourse.DisplayMember = "CourseName";
this.cmbCourse.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
this.cmbCourse.DropDownWidth = 160;
this.cmbCourse.Location = new System.Drawing.Point(347, 20);
this.cmbCourse.Name = "cmbCourse";
this.cmbCourse.Size = new System.Drawing.Size(253, 21);
this.cmbCourse.TabIndex = 3;
this.cmbCourse.ValueMember = "CourseID";

Here's how I'm trying to get the CourseID from the ComboBox:
DataRow newStudent = registerDataSet.Tables["Student"].NewRow();
// Other field stuff omitted.
newStudent["Course"]    = uint.Parse(cmbCourse.SelectedValue.ToString());

Any ideas why it's not returning the actual CourseID from SelectedValue? Thanks in advance, -hellz [Edited by - hellz on August 18, 2004 6:07:27 PM]

Share this post

Link to post
Share on other sites
Doh! Hate it when that happens.
I was about to post a test that I whipped up that seemed to work, but I guess you have it covered :)

Share this post

Link to post
Share on other sites
Yeah, spent 2 hours with that. [sad] Really hate it when things like that happen. It all seemed that it should work, but blah, no idea, lol.

Thanks for knocking up the test for me, though. Appreciate it. [smile] Guess I'll know better next time. [wink]


Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this