.NET Questions (CLOSED)

Questions and Answers on any aspect of .NET. Now closed.

This discussion group is now closed.

Have a question about .NET development? Try stackoverflow.com, a worldwide community of great developers asking and answering questions 24 hours a day.

The archives of .NET Questions contain years of Q&A. Even older .NET Questions are still online, too.

Setting a combobox selection

I intend to display records read from a database on a form. The database contains 2 tables, a table Job with 2 columns: ID and Occupation, and a table Person with Name and JobID. JobID refers to the row in the table Job with the same ID.

I have a combobox on the form which lists all the occupations (read from the database). These are objects with both a string Name and an int ID, the comboboxs displaymember and valuemember are set to these.
When a record from the table Person is read, the combobox should select the right occupation based on the field JobID.
Is this possible? Anything I found on comboboxes used them as input, while this is closer to output.
Patrik Van Ostaeyen Send private email
Tuesday, November 13, 2007
Very possible.  Under the appropriate event handler just do:

myComboBox.SelectedValue = myPerson.JobId

BTW, your DB naming convention looks a little suspect.

I'd use the following:

Job: Job_Id, Job_name
Person: Person_Id, Person_Name
Josh Kodroff Send private email
Tuesday, November 13, 2007
Got it to work. Thanks.
Patrik Van Ostaeyen Send private email
Wednesday, November 14, 2007
One thing about the combobox: the displaymember and valuemember expect a property. For the display member I already had a property, but for the valuemember not, it was declared as a public int. Making it a propery and using the selectedvalue made it work.
Patrik Van Ostaeyen Send private email
Friday, November 16, 2007

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics
Powered by FogBugz