?
Solved

aligning items in list box

Posted on 1998-08-12
3
Medium Priority
?
197 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 800 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

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 …
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
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…
Suggested Courses

840 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