?
Solved

Listbox : Need to have 2 columns

Posted on 2003-03-30
11
Medium Priority
?
556 Views
Last Modified: 2007-12-19
Hello!

  I have in my listbox


Name, firstname      (something)
Name2, firstname2      (something)
Name333, firstname333      (something)

The problem is that because the name and firstname it is not the same number of caracter, so my other information (something) it it not align.  So what I need is to have my other column (something) align.    And I know that vbTab is not working :-(

New result in my listbox I need is

Name, firstname            (something)
Name2, firstname2          (something)
Name333, firstname333      (something)


Thanks,
Narang
0
Comment
Question by:narang
[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
  • 4
  • 3
11 Comments
 
LVL 1

Expert Comment

by:robertlees
ID: 8237028
Solution 1. User Courier font (non-proportional) and pad the Name, FirstName to some maximum length.

List1.Additem Left(strName & ", " & strFirstName & space(20), 20) & strSomething)

Solution 2. User a Listview control instead of Listbox. This allows individual columns.

Solution 3. You can use the SendMessage API call to set tab stops within a Listbox.
0
 
LVL 1

Accepted Solution

by:
robertlees earned 150 total points
ID: 8237179
Solution 1. User Courier font (non-proportional) and pad the Name, FirstName to some maximum length.

List1.Additem Left(strName & ", " & strFirstName & space(20), 20) & strSomething)

Solution 2. User a Listview control instead of Listbox. This allows individual columns.

Solution 3. You can use the SendMessage API call to set tab stops within a Listbox.
0
 

Author Comment

by:narang
ID: 8237210
Hello!

  The problem I wrote an OCX with a listbox and the user in a textbox and write a name and it's find directly caractere by caractere the name.  So the initial specification was just a word.  But now the user wish to add this (something).

  If I knew before ... Listview or Grid will be better, but now I am in "it's for last year I wish this control".

So Solution 2, I can't now.

Solution 1, I already test it, but the problem is my specification of name,firstname is very urge. But that was not the problem because I can always trunc the name :-)
My problem is the USER wish to use is own font. :-(

Solution 3  :  Passing via SEndMessage API it is different from using vbTab ???  
Ex :List1.Additem Left(strName & ", " & strFirstName & vbTab & vbTab & strSomething)


The solution I have in mine is to hook the control and write a gotoX(number of Pixels or Twips) to go at the place I wish  on the current line.

   Somebody having experiencing that or other solution???

Thanks,
Narang
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!

 
LVL 2

Expert Comment

by:AKbor75
ID: 8237379
if you set list.columns=2 and adds an item like "hey;you" it will be sidplayed in 2 columns.
0
 

Author Comment

by:narang
ID: 8237701
Hi !

To Akbor75
  Nop list.columns=2 it is not what I need.  It display 2 columns but of the same data and the same problem.

To all others...

I found the solution...I don't have choice dead line arrive and USER cry .  Thank to Windows API :-)

For other that will have the same problem that me here I give a simple solution :

You just have to create 1 listbox on your form and copy that code and it will do the job I want and may be you want too :-)))

Option Explicit

Const LB_SETTABSTOPS = &H192  'set the tab-stop positions
Const LB_ADDSTRING = &H180    'add a string and re-sort a sorted listbox

Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Any) As Long
Private Declare Function SendMessageArray Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long

Private Sub Form_Load()
 Dim str  As String
 Dim MyTab As Long

 MyTab = 100

 Call SendMessageArray(List1.hwnd, LB_SETTABSTOPS, 0&, 0&)
 Call SendMessageArray(List1.hwnd, LB_SETTABSTOPS, 1&, MyTab)

 str = "Robert, Christian" & vbTab & "(Poly)"
 Call SendMessage(List1.hwnd, LB_ADDSTRING, 0&, str)
 str = "Winemiller, Jason T. Roff" & vbTab & "(Poly)"
 Call SendMessage(List1.hwnd, LB_ADDSTRING, 0&, str)
 str = "Gregoire" & vbTab & "(Poly)"
 Call SendMessage(List1.hwnd, LB_ADDSTRING, 0&, str)
 str = "Marchan, Sophie" & vbTab & "(Poly)"
 Call SendMessage(List1.hwnd, LB_ADDSTRING, 0&, str)

End Sub

Narang
0
 
LVL 1

Expert Comment

by:robertlees
ID: 8241283
Solution 3.
0
 
LVL 2

Expert Comment

by:AKbor75
ID: 8241560
i really thought it's not necissairy to use an api for a simple task like filling a list, so i tried... and found this working:

Private Sub FillListBox()
   
    ListBox1.Clear

    ListBox1.ColumnCount = 2
    ListBox1.ColumnWidths = "50 pt;50 pt"
   
    ListBox1.AddItem
    ListBox1.Column(0, 0) = "name"
    ListBox1.Column(1, 0) = "firstname"
   
    ListBox1.AddItem
    ListBox1.Column(0, 1) = "name2"
    ListBox1.Column(1, 1) = "firstname"
   
    ListBox1.AddItem
    ListBox1.Column(0, 2) = "name33"
    ListBox1.Column(1, 2) = "firstname33"
   
End Sub
0
 

Author Comment

by:narang
ID: 8241813
Hi AKbor75 ,

  I am in VB6 and the standard listbox don't have that function.  If you are in VB6 what is the name that control?
I know that in VB.NET you have more functionnality in the standard control, but my projet it is in old VB6 :-)
Thanks.
 


To robertlees,
  For sure that it is a part of solution 3, but you didn't gave me the wonderful API function that can help me to solve my problem.  And it is not just SendMessage, but SendMessageArray that is more useful otherwise SendMessage it's not useful.  Thanks.
 
0
 
LVL 2

Expert Comment

by:AKbor75
ID: 8249493
i used my function FillListbox in Listbox1_initialize in Excel VBA. didn't try it in VB5 (i don't have VB 6). thought that should work to... to bad it didn't.
may be the properties have different names? i'll check it out when i have time.
0
 
LVL 1

Expert Comment

by:robertlees
ID: 8251206
SendMessageArray is SendMessage by another name - look at their declarations. They are identical. SendMessage and SendMessageArray are both aliases for SendMessageA. You could just as easily have called it NarangFunction, and claim that I didn't tell you about NarangFunction...

Private Declare Function NarangFunction Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long

0
 

Author Comment

by:narang
ID: 8253352
Akbor75,
      Excel, Access and Word don't have the same control functionality.  In VB it is more basic .


Robertlees,
  lol  you are very funny.  I hope for me that I can reconize an alias :-)  

  But I did a mistake in my writing, it was the  LB_ADDSTRING I didn't know (no API documentation).  It's not a problem to give you the points, but next time try to be specific.  It is very easy to say SendMessage and not giving the syntaxe of the specific message.

Thanks to all :-)
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

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 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 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…
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…
Suggested Courses

741 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