Results 1 to 13 of 13

Thread: Tabs in ListBox

  1. #1

    Thread Starter
    Frenzied Member vbgladiator's Avatar
    Join Date
    May 2001
    Posts
    1,950

    Tabs in ListBox

    VB Code:
    1. Do Until rsClient.EOF
    2.             lstResult.AddItem rsClient("LastName") & vbTab & rsClient("FirstName") & vbTab & rsClient("ClientCode")
    3.             lstResult.ItemData(lstResult.NewIndex) = rsClient("ClientID")
    4.             rsClient.MoveNext
    5.         Loop
    6.        
    7.         SearchListTabs(1) = 50
    8.         SearchListTabs(2) = 120
    9.        
    10.         SendMessage lstResult.hWnd, LB_SETTABSTOPS, UBound(SearchListTabs) + 1, SearchListTabs(1)
    11.         lstResult.Refresh

    Why doesn't this work? It only shows the LastName and then the line is blank.

  2. #2
    Frenzied Member TheBionicOrange's Avatar
    Join Date
    Apr 2001
    Location
    Cardiff, UK
    Posts
    1,818
    Don't you need to declare everything after the first one (LastName) as 'Sub-Items' ?

  3. #3

    Thread Starter
    Frenzied Member vbgladiator's Avatar
    Join Date
    May 2001
    Posts
    1,950
    It's a listbox, not a listview.

  4. #4
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373
    no its a listbox not a listview.. i am guessing it is because you are tabbing in it.. try replacing the tabs with " " or something to see if it works

  5. #5

    Thread Starter
    Frenzied Member vbgladiator's Avatar
    Join Date
    May 2001
    Posts
    1,950
    I thought I needed the tabs in order to set tabs in the SendMessage function.

  6. #6
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373
    actually I just tested and the tabs don't mess it up..

    are you saying when you loop the record set it only shows the last name in the listbox?

    i tried
    VB Code:
    1. lstResult.AddItem "WORLD" & vbTab & "HELLO" & vbTab & "1234"
    2.     lstResult.ItemData(lstResult.NewIndex) = "1234"

    and it worked fine..

    or are you saying that the sendmessage part is not working?

  7. #7

    Thread Starter
    Frenzied Member vbgladiator's Avatar
    Join Date
    May 2001
    Posts
    1,950
    The data from the recordset works fine.

    Yes, It's the SendMessage that's not working.

  8. #8

    Thread Starter
    Frenzied Member vbgladiator's Avatar
    Join Date
    May 2001
    Posts
    1,950
    *Bump*

  9. #9
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373
    vbgladiator

    what does that sendmessage do to the listbox (or supposed to do)?

  10. #10
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333
    You need to set your Tabs BEFORE you populate your Listbox.
    VB Code:
    1. 'Example:
    2. Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
    3.  
    4. Private Const LB_SETTABSTOPS = &H192
    5.  
    6. Private Sub cmdLoadListBox_Click()
    7. 'set up the tabstops in the list boxes
    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

  11. #11

    Thread Starter
    Frenzied Member vbgladiator's Avatar
    Join Date
    May 2001
    Posts
    1,950
    This is my code:
    VB Code:
    1. SearchListTabs(0) = 50
    2.         SearchListTabs(1) = 120
    3.        
    4.         Call SendMessage(lstResult.hWnd, LB_SETTABSTOPS, 0&, ByVal 0&)
    5.         Call SendMessage(lstResult.hWnd, LB_SETTABSTOPS, UBound(SearchListTabs) + 1, SearchListTabs(0))
    6.  
    7.         Do Until rsClient.EOF
    8.             lstResult.AddItem rsClient("LastName") & vbTab & rsClient("FirstName") & vbTab & rsClient("ClientCode")
    9.             lstResult.ItemData(lstResult.NewIndex) = rsClient("ClientID")
    10.             rsClient.MoveNext
    11.         Loop
    12.  
    13.         lstResult.Refresh

    It still doesn't format the listbox.

  12. #12

    Thread Starter
    Frenzied Member vbgladiator's Avatar
    Join Date
    May 2001
    Posts
    1,950
    Found the problem.

    For some reason my declare line for SendMessage was expecting a string as the 4th argument instead of any.

    Thanks.

  13. #13
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333
    I just whipped this together, and it works perfectly
    VB Code:
    1. Private Sub Form_Load()
    2.     Set Db = OpenDatabase("c:\codelib\codelibrary.mdb")
    3.     SQL = "SELECT description, id FROM codeitems WHERE parentid = 1 ORDER BY description "
    4.     Set Rs = Db.OpenRecordset(SQL, dbOpenDynaset)
    5.     ReDim TabStop(0 To 1) As Long
    6.     TabStop(0) = 190
    7.     Do While Not Rs.EOF
    8.        Call SendMessage(List1.hwnd, LB_SETTABSTOPS, 0&, ByVal 0&)
    9.        Call SendMessage(List1.hwnd, LB_SETTABSTOPS, 1, TabStop(0))
    10.        List1.AddItem Rs(0) & Chr(9) & Rs(1)
    11.        Rs.MoveNext
    12.     Loop
    13. End Sub

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