There are multiple ways you can get where you want to go, but assuming that
you have to do it with an ArrayList and a Strucutre...
Add each struct into the the arraylist in the order they will appear in the
Listbox. At that point, ArrayList(0) will be equal to the listbox 0
itemname. Then you can just CType the ArrayList value TextBox1.Text
=CType(ArrayList(ListBox1.SelectedIndex), MyStruct).Make
TextBox2.Text = CType(ArrayList(ListBox1.SelectedIndex), MyStruct).Model
assuming Make and Model are both strings.
There's a lot undesirable about this approach, the most glaring of which is
storing Value types in a Reference type which can cause you a lot of
problems if you need to change things and you aren't familiar with Boxing
and dealing with value and reference types together.
A much easier way would be to use a Collection or a DataTable. Bind the
ListBox to the column that corresponds to the Make Model (set it's
DispalyMember to this). Use TextBox1.DataBindings.Add("text", DataSEt,
DataTable.ColumName) and a bindingcontext and then just set the text box's
text column to the respective field in the datatable. You can also bind to
a collection (and anything supporting the IList INterface) so that's
probably a more maintainable way to go.
HTH,
Bill
RBCC said:
I have a form with a listbox and two textboxes. In the listbox I have the
make and models of automobiles. and as the user clicks on the make of the
car in the listbox I would like to output the make and model in the
textboxes, how is this done with an arraylist?
Community Website:
http://www.dotnetjunkies.com/newsgroups/