Solved

formated list box

Posted on 2000-04-27
11
228 Views
Last Modified: 2010-05-02
Is there a way to format a list box so there are 2 columns of items the right side is right justified and the left side is left justified?

Craig
0
Comment
Question by:csindorf
  • 4
  • 3
  • 2
  • +1
11 Comments
 
LVL 1

Expert Comment

by:yfang
ID: 2757211
The first method I would try is to put spaces between the two items ("item1" & "a number of spaces" & "item2") before you populate the listbox.  It should be easy to determine how many spaces you need between any specific pair of items, based on the width of the listbox (list1.width), the lengths of the items (len("item1"), len("item2")).  Then you can use a loop to add the number of spaces.
0
 
LVL 32

Expert Comment

by:bhess1
ID: 2757237
Check this reference:

http://www.thescarms.com/vbasic/listbox.htm

It provides a sample of setting tab stops, including right justified tab stops, in a listbox.
0
 

Expert Comment

by:richking042700
ID: 2757460
If you want, you can set the listbox Columns property to 2 and this would split the list box into two columns.
0
 

Author Comment

by:csindorf
ID: 2759398
Adjusted points from 20 to 30
0
 

Author Comment

by:csindorf
ID: 2759399
If I set the property to 2 columns then how do I enter the items into them and right and left justify?  Because the items going into the columns might be different lengths so I would want the first letter of the first item on the far left and the last letter of the other item on the far right.

Info:  the first column will be a list of part numbers then in the right column will be there one word description.  ex:

123445        washer
53453466         nut
23d          ferrule
0
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 

Author Comment

by:csindorf
ID: 2759795
Adjusted points from 30 to 50
0
 

Author Comment

by:csindorf
ID: 2759796
Question only partially answered.  I saw the column property.  But not a way to left and right justify.

Could yfang go into a bit more detail please?  I have not been into VB for 2 years now but my new contract has put me into the mode again to learn and cram fast.

A bit more info is that I will be hitting a Database and pulling out part numbers and their descriptions.  I then need to put them into a list box.  The formatting is an extra bonus I am trying to do. So when the user looks at the list there are spaces or tabs between the items, which can be different lengths.

TIA
Craig
0
 
LVL 32

Expert Comment

by:bhess1
ID: 2759897
There is no way without using SendMessage to right justify a column in a list box.

Did you check the link I referenced above on how to set right justified tab stops in a listbox?
0
 

Accepted Solution

by:
richking042700 earned 50 total points
ID: 2759924
Switch to a Mono space font.  Then you pad the variable.

Example:

'USE a Mono space font like Courier
Private Sub Form_Load()

    Dim strStringOne As String * 15
    Dim strStringTwo As String
   
    'Quick little example just to show you.
    For i = 1 To 10
        strStringOne = "Apples" & i * i
        strStringTwo = strStringOne & CStr(i)
        List1.AddItem strStringTwo
    Next
   
End Sub

0
 
LVL 32

Expert Comment

by:bhess1
ID: 2759961
One other possibility:  The free CoolTabs control from the Common Control Replacement Project's CoolTools collection at:

http://www.mvps.org/ccrp/download/cooltools.htm

To look over all of there controls, go to their home page:

http://www.mvps.org/ccrp/index.html

Really useful stuff to be found here!
0
 
LVL 1

Expert Comment

by:yfang
ID: 2761098
Here is a simple way to to it:

1. Set the font of your listbox to "Courier" since with this font all the characters are the same fat.
2. One your listbox is drawn, you can test how many characters it will hold.
3. Code similar to this:

Private Sub Command1_Click()
 Dim str1 As String, str2 As String
 Dim str As String
 Dim LengthList As Integer
 list1.Font = "Courier"
 str = "abcdefghijklmno"
 LengthList = LenB(str)
 list1.AddItem str
 str1 = "test1"
 str2 = "terere2"
 str = str1
 Do
    str = str & " "
 Loop Until LenB(str) = Fix((LengthList - LenB(str2)))
 str = str & str2
 list1.AddItem str

End Sub

Note: the Loop ... and ((LenthList ...
actually belong to the same line.  If you have any problem with this, feel free to email me at: yfang@lawco.com

Good luck!

0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
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…
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…

747 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

11 Experts available now in Live!

Get 1:1 Help Now