General information
Title:
Finding Index of item in combobox
How do I set a combobox to a specific item in the
list based on the value of the ValueMember for that
item?
Scenario: user double clicks row in grid for editing.
App creates and populates myCar object from selected
record in grid.
myCar.VehicleID = 7;
myCar.VehicleType = 3;
myCar.Name = "Corolla";
Next an edit form is created and populated with
existing values for the Car object.
frmEditVehicle.txtName = myCar.Name;
frmEditVehicle.txtID = myCar.ID;
NOTE: at this point all vehicle types have already
been loaded into the cboVehicleType combobox.
frmEditVehicle.cboVehicleType.SelectedIndex = ???;
What I know here is that the ValueMember for the item
in the combobox that I want to select is 3. However,
the Index number for the item may be 2, or something
else. What is the best-practice method for doing this
in .NET?
Next
Reply
View the map of this thread
View the map of this thread starting from this message only
View all messages of this thread
View all messages of this thread starting from this message only