Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Finding Index of item in combobox
Message
From
23/01/2003 10:27:33
 
 
To
23/01/2003 07:26:07
David Bradford
Georgia Department of Revenue
Lawrenceville, Georgia, United States
General information
Forum:
ASP.NET
Category:
Forms
Miscellaneous
Thread ID:
00744672
Message ID:
00744731
Views:
22
This message has been marked as the solution to the initial question of the thread.
I think the property you want is the SelectedValue property.

Typically, I DataBind the DataColumn to the SelectedValue property of the ComboBox, but it doesn't appear that you are using a Table. Still, I believe that you can DataBind your UI objects to your myCar object, something like this:
this.cboVehicleType.DataBindings.Add("SelectedValue", myCar, "VehicleType");
Although, I believe that your myCar object needs to implement an interface, but I'm not sure which one (because I've always data bound to Tables).

Anyway, this might point in you in the right direction ... if not, someone else will chime in, I'm sure, with a better answer. <g>

~~Bonnie


>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?
Bonnie Berent DeWitt
NET/C# MVP since 2003

http://geek-goddess-bonnie.blogspot.com
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform