Solved

aligning items in list box

Posted on 1998-08-12
3
193 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

Question has a verified solution.

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

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
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…
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…

688 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