Solved

aligning items in list box

Posted on 1998-08-12
3
190 Views
Last Modified: 2010-04-30
how do i align items in a list box.....
i  concatenate 3 fields and then add it to a list box but the next 3 does not align with the first....any way to align it....
thanks

 
0
Comment
Question by:wenchang
  • 2
3 Comments
 
LVL 14

Accepted Solution

by:
waty earned 200 total points
ID: 1468642
To align items in a listbox, you have to set a fexed font (system)

Another solution is settings tabstops

Private Declare Function SendMessageLong Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long

Private Const LB_SETTABSTOPS = WM_USER + 19

Sub CBLTabStops(CBL As Control, nNbTab As Integer, nTab() As Integer)
    ' *** Create tabstop to aliogn columns
    ' nNbTab = Nbr of tabs
    ' nTab() = Size of each column in pixels

    Dim lResponse As Long

    lResponse = SendMessageLong(CBL.hwnd, LB_SETTABSTOPS,
     nNbTab, nTab(0))

End Sub

0
 
LVL 14

Expert Comment

by:waty
ID: 1468643
I forgot to give you the way to write to column :

Sub CBLWriteCol(CBL As Control, ByVal nLigne As Integer, ByVal nCol As Integer, szCol As String)
    ' *** Write for a specific ling in a column
    Dim szLigne       As String
    Dim szNewLine     As String
    Dim lIndex        As Long
    Dim iIndice       As Integer
    Dim nPositionTab  As Integer
    Dim nPositionFin  As Integer
   
    szLigne = CBL.List(nLigne)
    lIndex = CBL.ItemData(nLigne)
   
    '*** Seek beginning of column
    nCol = nCol + 1
    nPositionTab = 1
    Do While nCol > 1
        nPositionTab = InStr(nPositionTab, szLigne, Chr$(9))
        If nPositionTab = 0 Then Exit Sub
        nPositionTab = nPositionTab + 1
        nCol = nCol - 1
    Loop
   
    '*** End of column
    nPositionFin = InStr(nPositionTab, szLigne, Chr$(9))
   
    If nPositionFin = 0 Then
        nPositionFin = Len(szLigne)
    Else
        nPositionFin = nPositionFin - 1
    End If
   
    szNewLine = ""
    If nPositionTab > 1 Then szNewLine = szNewLine & Left$(szLigne, nPositionTab - 1)
    szNewLine = szNewLine & szCol
   
    If nPositionFin < Len(szLigne) Then szNewLine = szNewLine & Right$(szLigne, Len(szLigne) - nPositionFin)
    CBL.RemoveItem nLigne
    CBL.AddItem szNewLine, nLigne
    CBL.ItemData(CBL.NewIndex) = lIndex

End Sub





And finally, here is a way to add scrollbar

Private Declare Function SendMessageLong Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Private Const LB_SETHORIZONTALEXTENT = (WM_USER + 21)

Sub CBLSetHScroll(CBL As Control, nLen As Integer, nAvgCharWidth As Integer)

   Dim lResponse  As Long
   
   lResponse = SendMessageLong(CBL.hwnd, LB_SETHORIZONTALEXTENT, nLen * nAvgCharWidth, 0&)
   CBL.Refresh

End Sub


0
 
LVL 8

Expert Comment

by:mrmick
ID: 1468644
You will find great examples of using columns in a listbox at:

http://www.mvps.org/vbnet/

Click "Code Library" and then "List & Combo"
0

Featured Post

ScreenConnect 6.0 Free Trial

Explore all the enhancements in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI, app configurations and chat acknowledgement to improve customer engagement!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
VB6 Compile Compatibility Issue 4 102
Added a column screws up code 5 58
Zip Folders Using Chilkat Routines 1 41
Send outlook email from VBS Script 2 31
Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

832 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question