Results 1 to 11 of 11

Thread: [RESOLVED] Columns property of List box - How to use?

  1. #1

    Thread Starter
    VB Addict Pradeep1210's Avatar
    Join Date
    Apr 2004
    Location
    Inside the CPU...
    Posts
    6,614

    Resolved [RESOLVED] Columns property of List box - How to use?

    I did this long ago - multiple columns in listbox, but now I seem to have forgot how to do it

    Can someone please help me with this? How do we use the Columns property of the standard listbox control?

    Pradeep
    Pradeep, Microsoft MVP (Visual Basic)
    Please appreciate posts that have helped you by clicking icon on the left of the post.
    "A problem well stated is a problem half solved." — Charles F. Kettering

    Read articles on My Blog101 LINQ SamplesJSON ValidatorXML Schema Validator"How Do I" videos on MSDNVB.NET and C# ComparisonGood Coding PracticesVBForums Reputation SaverString EnumSuper Simple Tetris Game


    (2010-2013)
    NB: I do not answer coding questions via PM. If you want my help, then make a post and PM me it's link. If I can help, trust me I will...

  2. #2
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Columns property of List box - How to use?

    Why do you want to put yourself through that torture when using a Listview is some much simpler and much easier to programmatically deal with?

  3. #3

    Thread Starter
    VB Addict Pradeep1210's Avatar
    Join Date
    Apr 2004
    Location
    Inside the CPU...
    Posts
    6,614

    Re: Columns property of List box - How to use?

    Quote Originally Posted by Hack
    Why do you want to put yourself through that torture when using a Listview is some much simpler and much easier to programmatically deal with?
    It is slower than the standard listbox and I'll be frequently adding and removing rows from it.
    Pradeep, Microsoft MVP (Visual Basic)
    Please appreciate posts that have helped you by clicking icon on the left of the post.
    "A problem well stated is a problem half solved." — Charles F. Kettering

    Read articles on My Blog101 LINQ SamplesJSON ValidatorXML Schema Validator"How Do I" videos on MSDNVB.NET and C# ComparisonGood Coding PracticesVBForums Reputation SaverString EnumSuper Simple Tetris Game


    (2010-2013)
    NB: I do not answer coding questions via PM. If you want my help, then make a post and PM me it's link. If I can help, trust me I will...

  4. #4
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Columns property of List box - How to use?

    Ok, fine. Here is an example of how to use TabStops to set up columns. You will need to play around with widths and stuff like that until it gets you what you need/want.
    VB Code:
    1. Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" _
    2. (ByVal hwnd As Long, ByVal wMsg As Long, _
    3. ByVal wParam As Long, lParam As Any) As Long
    4.  
    5. Private Const LB_SETTABSTOPS = &H192
    6.  
    7. Private Sub Form_Load()
    8.    ReDim TabStop(0 To 2) As Long
    9.  
    10.   'assign some values to the tabs for the second third and fourth
    11.   'column (the first is flush against the listbox edge)
    12.    TabStop(0) = 90
    13.    TabStop(1) = 130
    14.    TabStop(2) = 185
    15.  
    16.   'clear then set the tabs
    17.    Call SendMessage(List1.hwnd, LB_SETTABSTOPS, 0&, ByVal 0&)
    18.    Call SendMessage(List1.hwnd, LB_SETTABSTOPS, 3, TabStop(0))
    19.     List1.AddItem "Big" & Chr(9) & "Brown" & Chr(9) & "Dog"
    20.     List1.AddItem "Brown" & Chr(9) & "Big" & Chr(9) & "Dog"
    21.     List1.AddItem "Dog" & Chr(9) & "Brown" & Chr(9) & "Big"
    22.     List1.Refresh
    23. End Sub

  5. #5

    Thread Starter
    VB Addict Pradeep1210's Avatar
    Join Date
    Apr 2004
    Location
    Inside the CPU...
    Posts
    6,614

    Re: Columns property of List box - How to use?

    Thanks a lot Hack,

    This would work fine for me.

    But I remember I made multi-column list box without using any API's in the past. Now I can't figure how I did it. It was probably someway using the Columns property, but I'm not sure.
    I was curious to know what is the Columns property for and how do we use it.

    Pradeep
    Pradeep, Microsoft MVP (Visual Basic)
    Please appreciate posts that have helped you by clicking icon on the left of the post.
    "A problem well stated is a problem half solved." — Charles F. Kettering

    Read articles on My Blog101 LINQ SamplesJSON ValidatorXML Schema Validator"How Do I" videos on MSDNVB.NET and C# ComparisonGood Coding PracticesVBForums Reputation SaverString EnumSuper Simple Tetris Game


    (2010-2013)
    NB: I do not answer coding questions via PM. If you want my help, then make a post and PM me it's link. If I can help, trust me I will...

  6. #6
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Columns property of List box - How to use?

    Quote Originally Posted by Pradeep1210
    Thanks a lot Hack,

    This would work fine for me.

    But I remember I made multi-column list box without using any API's in the past. Now I can't figure how I did it. It was probably someway using the Columns property, but I'm not sure.
    I was curious to know what is the Columns property for and how do we use it.

    Pradeep
    I really don't know Pradeep. I used the code I posted for mutliple listbox lines before the ListView came out (or before I learned how to use it, I can't remember which now. ). I'm sure you could find something through Google or MSDN on the Columns property though.

  7. #7

    Thread Starter
    VB Addict Pradeep1210's Avatar
    Join Date
    Apr 2004
    Location
    Inside the CPU...
    Posts
    6,614

    Re: Columns property of List box - How to use?

    There was one more thing I was curious about in this forum...

    Why can't I rate someone's post who helped me recently and now helped me again.
    Pradeep, Microsoft MVP (Visual Basic)
    Please appreciate posts that have helped you by clicking icon on the left of the post.
    "A problem well stated is a problem half solved." — Charles F. Kettering

    Read articles on My Blog101 LINQ SamplesJSON ValidatorXML Schema Validator"How Do I" videos on MSDNVB.NET and C# ComparisonGood Coding PracticesVBForums Reputation SaverString EnumSuper Simple Tetris Game


    (2010-2013)
    NB: I do not answer coding questions via PM. If you want my help, then make a post and PM me it's link. If I can help, trust me I will...

  8. #8
    PowerPoster BruceG's Avatar
    Join Date
    May 2000
    Location
    New Jersey (USA)
    Posts
    2,657

    Re: Columns property of List box - How to use?

    My two cents:
    The Columns property of the listbox simply enables you to "snake" the items in the list (i.e. take your list of items and show them in "newspaper" columns). The Columns property is NOT intended for showing different columns (fields) of a row (record) of data.

    To show different columns of data in each row, the ListView is the best suggestion, as Hack mentioned. To use the standard listbox, you can set up tabs as Hack suggests, or, a low-tech but effective solution is to first use a monospaced font (such as Courier) for the listbox, then format each string of data with the same amount of positions for each field (padding with blank spaces as necessary).
    "It's cold gin time again ..."

    Check out my website here.

  9. #9
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431

    Re: Columns property of List box - How to use?

    Quote Originally Posted by Pradeep1210
    There was one more thing I was curious about in this forum...

    Why can't I rate someone's post who helped me recently and now helped me again.
    The FAQ for ratings explains it when it says (in part)
    You must give reputations to 10 different people before you can come back to the same person again.

  10. #10

    Thread Starter
    VB Addict Pradeep1210's Avatar
    Join Date
    Apr 2004
    Location
    Inside the CPU...
    Posts
    6,614

    Re: Columns property of List box - How to use?

    Thanks all !

    Problem resolved.

    Pradeep
    Pradeep, Microsoft MVP (Visual Basic)
    Please appreciate posts that have helped you by clicking icon on the left of the post.
    "A problem well stated is a problem half solved." — Charles F. Kettering

    Read articles on My Blog101 LINQ SamplesJSON ValidatorXML Schema Validator"How Do I" videos on MSDNVB.NET and C# ComparisonGood Coding PracticesVBForums Reputation SaverString EnumSuper Simple Tetris Game


    (2010-2013)
    NB: I do not answer coding questions via PM. If you want my help, then make a post and PM me it's link. If I can help, trust me I will...

  11. #11
    Lively Member
    Join Date
    Dec 2013
    Location
    Iran
    Posts
    108

    Question Re: Columns property of List box - How to use?

    hi
    i have a problem gays
    i have a text file whit name "Database.txt" inside my program exe file.
    my Database.txt info is:

    ali*hashemi*0310967600*1363.10.05*90*90128118
    reza*hashemi*03109676022*1361.05.08*91*90128119


    i how read this file and split by * and show thats in listbox whit Columns?
    thanks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width