ListBox

How do I list more than one column from my database to my listbox It will only let me do one column.


Answer this question

ListBox

  • Marc2002

    Hi,

    Try This

    You can change the values of the display variable.

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

    Dim display As String = "ron" + " " + "nash"

    With ListBox1

    .Items.Clear()

    .DisplayMember = "display"

    .Items.Add(display)

    End With

    End Sub

    Hope this Helps


  • AliSyed

    I tried to combine it and I get this message in my listbox

    System.Data.DataRowView

    Here's how I coded it.

    Me.ListBox1.DataSource = DbDataSet.Names

    Me.ListBox1.DisplayMember = "FirstName" + "LastName"



  • Calmin

    Hi.

    Is your problem solved

    Thank you,
    Bhanu.



  • Kelvin Lush

    That is correct - this listbox is designed to show a single column of items.

    If you want to display more than one item you have a couple of options - concatenate (combine) the items into a single string that you can add the to the listbox

    Example

    List Items 1 (First)
    List Items 2 / (Second)
    List Items 3 | (Third)

    Where the second item you want is wrapped in parenthesis or separated by / or | characters of something like that. Often not an ideal solution.

    Another is to use a Listviewcontrol which you can establish in a details view mode and it in effect acts like a multi column listbox - takes a bit more effort to populate it but this may be an option.

    Or find a third party custom control that enables you to do a multi column listbox (suppliers like infragistics and Component One are two that have a range of controls which go beyond the basic windows controls supplied )

    In my opinion a multi column listbox is something which I would have like for years now in the standard controls but it hasnt appeared so depending upon the circumstances you have to work around it..


  • bwells

    You cant do that with databinding the display member has to be a single field in the data source.

    Concatenating is possible if you are manually populating the listbox by iterating through a dataset and combining the values of multiple fields into a string, or you could modify the SQL statement that populates the datasource so there is a single field which is a combination of the fields you want to display - that way you displaymember will still be a single field in the datasource.


  • ListBox