Question combobox / txt file problem

bert aalders

Member
Joined
Mar 4, 2011
Messages
16
Programming Experience
Beginner
i am new and trying to learn vb, i always used Delphi
I have the next problem.
i have a txt file filled with locations of databases.

database_a = c:\dba
database_b = c:\dbb
databace_c = c:\dbc

i read the data into the combobox but only the name can be visible

Dim objStreamReader As New StreamReader(Testmap & "\test.txt")
Do While objStreamReader.Peek <> -1
databasekeuze.Items.Add((objStreamReader.ReadLine()).Split("=")(0))
Loop
objStreamReader.Close()

after selecting the correct database in need the location
selecting databaseb, should give me the correct possition in this case c:\dbb
how do i do this or am i starting wrong

newby
 
You basically need to create a mapping between the items in the list of left-hand values and the items in the list of right-hand values. There are a number of ways that you could do this but I would suggest doing it via data binding. You will first need to define a type, i.e. a class or structure, to represent a list of value pairs. I would suggest a structure with Text and Value properties, both type String. You can then create a generic List of that type. As you read the file, you'll split each line, create an instance of your type, assign the two values from the line of the file to its properties and then add the item to the List.

Now that you have a populated list, you can bind it to the ComboBox. First, set the DisplayMember of the ComboBox to the name of the property of each item that you want to display in the control, i.e. "Text". Likewise, set the ValueMember to the name of the other property. You can then assign the list itself to the DataSource. When the user makes a selection from the ComboBox, you use the SelectedValue property to get the appropriate value.
 
Back
Top