Tech or Treat! Write an article about your scariest tech disaster to win gadgets!Learn more

x
?
Solved

formated list box

Posted on 2000-04-27
11
Medium Priority
?
243 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
[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
  • 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
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…
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…
Suggested Courses

647 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