0

I have a coupple of listboxes with the same object type in all of them, the problem i have is that i dont want the object displayed with the same ToString() method in all of the listboxes. Is there a way to solve this?

At the moment im adding strings to the listboxes and then i use the selected string to search a list of objects for the correct one but i dont like that solution at all.

1 Answer 1

2

Suppose to have a class for Employees like this one:

Public Class Employee
    Public Property ID As Integer
    Public Property FirstText As String
    Public Property SecondText As String
    ' and go on with other properties
    ....
End Class

Now when you populate your listboxes, you set the DisplayMember and ValueMember of your listboxes to two different property of Employee

Dim myList As ArrayList = New ArrayList()
myList.Add(New Employee() With {.ID = 1, .FirstText = "John Doe", .SecondText = "Doe John"})
myList.Add(New Employee() With {.ID = 2, .FirstText = "Mark Ross", .SecondText = "Ross Mark"})

ListBox1.DataSource = myList
ListBox2.DataSource = myList

ListBox1.ValueMember = "ID"
ListBox1.DisplayMember = "FirstText"

ListBox2.ValueMember = "ID"
ListBox2.DisplayMember = "SecondText"
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.