2 Replies - 4350 Views - Last Post: 12 July 2012 - 06:18 AM Rate Topic: -----

#1 Vishal1419  Icon User is offline

  • D.I.C Head

Reputation: 4
  • View blog
  • Posts: 141
  • Joined: 19-May 12

Multi-Column Listbox in vb.net

Posted 12 July 2012 - 12:24 AM

I spent many hours on searching a Multi-Column listbox
All of them suggests to use either a listview or datagridview
but my project contains many listboxes and i think it will not be an easy task for me to change the controls

So i came up with a solution by playing with Len() of items

Here is my code

    For dataCount As Integer = 0 To dsItems.Tables("tblStockItems").Rows.Count - 1
            Dim num As Integer
            num = 40 - Len(dsItems.Tables("tblStockItems").Rows(dataCount).Item(0).ToString)
              lstItems.Items.Add(dsItems.Tables("tblStockItems").Rows(dataCount).Item(0).ToString & Space(num) & dsItems.Tables("tblStockItems").Rows(dataCount).Item(1).ToString)
    Next




But i didnt get the listbox to look like two columns
Picture below demonstrates my problem

Attached image(s)

  • Attached Image


Is This A Good Question/Topic? 0
  • +

Replies To: Multi-Column Listbox in vb.net

#2 drec  Icon User is offline

  • New D.I.C Head

Reputation: 3
  • View blog
  • Posts: 42
  • Joined: 06-July 12

Re: Multi-Column Listbox in vb.net

Posted 12 July 2012 - 03:22 AM

let us say d possible max length of strings is less than 30

        Dim mytab1 As String = vbTab
        Dim mytab2 As String = vbTab & vbTab
        Dim mytab3 As String = vbTab & vbTab & vbTab
        Dim mytabs As String

        For dataCount As Integer = 0 To dsItems.Tables("tblStockItems").Rows.Count - 1
            Dim num As Integer
            num = Len(dsItems.Tables("tblStockItems").Rows(dataCount).Item(0).ToString)

            If num > 10 And num < 20 Then
                mytabs = mytab2
            ElseIf num > 20 And num < 30 Then
                mytabs = mytab1
            Else
                mytabs = mytab3
            End If

            lstItems.Items.Add(dsItems.Tables("tblStockItems").Rows(dataCount).Item(0).ToString & mytabs & dsItems.Tables("tblStockItems").Rows(dataCount).Item(1).ToString)
        Next


This post has been edited by drec: 12 July 2012 - 03:25 AM

Was This Post Helpful? 0
  • +
  • -

#3 sela007  Icon User is offline

  • D.I.C Addict

Reputation: 138
  • View blog
  • Posts: 838
  • Joined: 21-December 11

Re: Multi-Column Listbox in vb.net

Posted 12 July 2012 - 06:18 AM

Quote

I spent many hours on searching a Multi-Column listbox

and you didn't find listview?? Listviev is just multi-column listbox.
I warmly recommend you to change your controls, and do this in a proper way.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1