Information générale
Titre:
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?
Suivant
Répondre
Voir le fil de ce thread
Voir le fil de ce thread à partir de ce message seulement
Voir tous les messages de ce thread
Voir tous les messages de ce thread à partir de ce message seulement