Jump to content
  • Advertisement
Sign in to follow this  
hellz

[.net] ComboBox.ValueMember/SelectedValue - Solved

This topic is 5053 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
Advertisement
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]

-hellz

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!