Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Listbox Column Widths

Status
Not open for further replies.

RobM76

Technical User
Feb 6, 2008
17
CA
Hi,

I have a list box that I populate from a listview using additem with vbtab's inbetween.

The problem I have is that if the text in a cell is long it pushes the next colomn over, and I would like to set column widths so this does not happen.

Ai am using
Dim tabs(7) As Long
tabs(0) = 20
tabs(1) = 50
tabs(2) = 90
tabs(3) = 199
tabs(4) = 300
tabs(5) = 330
tabs(6) = 360

which only specify the starting position, I assume?

Can anyone please help
 
You may want to use a fixed lenght Font for your Listbox.

If you are using true Font, like Tacoma or Arial, 5 letters 'w' ( will take a lot more space than 5 i's (iiiii)

If you decide to use Courier New Font, you may just do this:
Code:
First    Second     Third
Bill     Susie      Samantha
Abcdefgh Ijklmnajhr 123
detecting the number of letters and adding appropriate number of Spaces.


Have fun.

---- Andy
 
Hi Andy,

I was using MS Sans Serif before but I changed it to Courier, but it still pushes the next column over, so if I have 2 values here below

Name Address
Barry Newman Here

instead of getting neat columns like this

Name Address
Barry Ne Here

I get this

Name Address
Barry Newman Here

is there no setting that I can specify widths of columns, or a different way to display the items and make them selectable??

Thanks
 
RobM76 said:
instead of getting neat columns like this

Name Address
Barry Ne Here
You could pad and trim the values, e.g. (to get 8 characters and a seperating space as per your example)
Code:
Debug.Print Left(strval & Space$(8), 8) & Space$(1)
Hope this helps

HarleyQuinn
---------------------------------
The most overlooked advantage to owning a computer is that if they foul up there's no law against wacking them around a little. - Joe Martin

Get the most out of Tek-Tips, read FAQ222-2244 before posting.
 
Thats a good idea, I think I will have to go with that!

Its a bit stupid that you can't set the column widths, since list boxes are supposed to be neat!!

Wierd!

Thanks again for your help!!
 
Have you thought about using a Grid, or FlexGrid instead of a listbox?
 
I'm new to VB6 so no!

Would they display the data better??

I will look into is and see if its better,

thanks.
 
RobM76 said:
Its a bit stupid that you can't set the column widths, since list boxes are supposed to be neat!!
I'm pretty sure we've already had the conversation that listboxes only support one column so we're/you're just mimicking the display of multiple columns, you've still only got one column... [wink]

HarleyQuinn
---------------------------------
The most overlooked advantage to owning a computer is that if they foul up there's no law against wacking them around a little. - Joe Martin

Get the most out of Tek-Tips, read FAQ222-2244 before posting.
 
Why not just stick to the listview? In report view, with column headers hidden, full row select selected and manual edit mode activated it looks pretty much like a list box with colums- and you get full control over column widths.
 
Ok, fair enough.

But is there then a multicolumn display available instead of a list box?

Is a grid a solution like waytech suggested?
 
*cough* ListView as strongm said...

HarleyQuinn
---------------------------------
The most overlooked advantage to owning a computer is that if they foul up there's no law against wacking them around a little. - Joe Martin

Get the most out of Tek-Tips, read FAQ222-2244 before posting.
 
yes, a listview in Report mode.

Or a grid, sure.

But given your data is already in a listview ... it seems to make sense to keep it in a listview (and it also solves your query about addressing individual columns raised in thread222-1448541)
 
Sorry I did not see the OP was using a "Listview" control, as I read "Listbox" in the subject line...
 
waytech2003 - He is using a listbox, but the data's being populated from a listview [smile]

HarleyQuinn
---------------------------------
The most overlooked advantage to owning a computer is that if they foul up there's no law against wacking them around a little. - Joe Martin

Get the most out of Tek-Tips, read FAQ222-2244 before posting.
 
Thanks for all your help guys, I did the tweaks to th list view and now it is showing the data the way I want!

I just checked the full row select and it was fine.

Thanks again for all your advice!
 
<Its a bit stupid that you can't set the column widths
The point is that the listbox control doesn't support multiple columns, and that's why you can't set the column widths. There aren't any columns to set the widths of! You can dummy up columns either using tabs or fixed width fonts and spaces. But trust me, it's a real pain. Strongm's solution is better.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top