Wrox Home  
Search P2P Archive for: Go

  Return to Index  

pro_vb thread: Listbox with columns


Message #1 by jiwilliams@c... on Mon, 25 Nov 2002 16:50:32
Yup, you're right.  You need to be aware of the length of your data.  The
tab stops behave the same way they do in a word processing document.

*shrug*

--
Jeff Mason              Custom Apps, Inc.
Jeff@c...


-----Original Message-----
From: Mark Roworth [mailto:mark.roworth@b...]
Sent: Monday, November 25, 2002 12:27 PM
To: professional vb
Subject: [pro_vb] RE: Listbox with columns


I've used this in the past. If works fine until one of your pieces of data
exceeds the width you have specified with the tabs stops, and then all the
fields get shifted across one column.

-----Original Message-----
From: Jeff Mason [mailto:je.mason@a...]
Sent: 25 November 2002 17:23
To: professional vb
Subject: [pro_vb] RE: Listbox with columns


There is another way.  Some others have suggested using a ListView, and that
may be better than a listbox, depending on what you intend to do with it.

It turns out you can set tab stops in a listbox, by using the Windows
SendMessage API.  You can set a number of tab stops in the listview, and
then any text inserted into the listbox which has embedded tab characters
will have the text aligned at the stops set.  You use the SendMessage API to
send a SetTabStops message to the listbox, and pass it the address of an
array of tab stop settings.  The array is an array of longs, and the entries
define tab stops in dialog box units (about 1/4 of a character width).  You
may have to experiment to get the values correct.

Use the following declarations:

	Public Declare Function SendMessage Lib "user32.dll" _
		Alias "SendMessageA" (ByVal hWnd as Long, ByVal wMsg as Long, & _
			ByVal lParam As Any) as Long

	Public Const LB_SETTABSTOPS = &H192

The SendMessage call takes the number of tab stops to set, and the array as
parameters.  To set three tab stops, e.g.:

	Dim Tabpos(2) as long

	Tabpos(0)=10
	Tabpos(1)
	Tabpos(2)=30

then

	Call SendMessage(YourListBox.hWnd, LB_SETTABSTOPS, 3, Tabpos(0))

Then embed tab characters, chr$(9), at the appropriate position in the
string you add to the listbox.
--
Jeff Mason              Custom Apps, Inc.
Jeff@c...


  Return to Index