• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 568
  • Last Modified:

Listbox : Need to have 2 columns

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
narang
Asked:
narang
  • 4
  • 4
  • 3
1 Solution
 
robertleesCommented:
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
 
robertleesCommented:
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
 
narangAuthor Commented:
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
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
AKbor75Commented:
if you set list.columns=2 and adds an item like "hey;you" it will be sidplayed in 2 columns.
0
 
narangAuthor Commented:
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
 
robertleesCommented:
Solution 3.
0
 
AKbor75Commented:
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
 
narangAuthor Commented:
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
 
AKbor75Commented:
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
 
robertleesCommented:
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
 
narangAuthor Commented:
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: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

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.

  • 4
  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now