?
Solved

formated list box

Posted on 2000-04-27
11
Medium Priority
?
245 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:Brendt Hess
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
Independent Software Vendors: 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!

 

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
 

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:Brendt Hess
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 200 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:Brendt Hess
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

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Question has a verified solution.

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

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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
Course of the Month16 days, 13 hours left to enroll

864 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