Solved

aligning items in list box

Posted on 1998-08-12
3
191 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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
message box in access 4 51
How does CurrentUser work? 10 38
How to compare ms sql hashbytes results within vb6 5 84
Visual Studio 2005 text editor 10 44
Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
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…
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…

861 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