Solved

aligning items in list box

Posted on 1998-08-12
3
188 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
Comment Utility
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
Comment Utility
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
Comment Utility
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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
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 Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

744 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now