Sign in to follow this  

[.net] ComboBox.ValueMember/SelectedValue - Solved

This topic is 4870 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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

-hellz

Share this post


Link to post
Share on other sites

This topic is 4870 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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