Listbox Columns

  • Thread starter Thread starter aaj
  • Start date Start date
A

aaj

Hi all

I'm having a really stupid problem with listboxes

I have dropped a listbox on a form and I want to configure the columns

I just want a single column, but it seems that another blank one is created
by default to the right hand side

If I set the list box as width 150 and add a column

LSTProcessList.Columns.Add(New ColumnHeader)
LSTProcessList.Columns(0).Text = "Ref1"
LSTProcessList.Columns(0).Width = 150

Then I can grab the top of the column called Ref1, move it to the left and
there is a blank one to the right.

Is there any way that I can have one single column that scrolls up and down,
but not left and right.

thanks

Andy
 
AAJ,

A listbox has only one vertical column or one vertical row (multicolomn).
Is that the problem?

I hope this helps,

Cor
 
Hi Andy,

Listboxes in vb .net do not have a columns.add method. Is this a custom
listbox? A listview?

Bernie Yaeger
 
aaj said:
I'm having a really stupid problem with listboxes

I assume you are talking about a listview control...
I have dropped a listbox on a form and I want to configure the columns

I just want a single column, but it seems that another blank one is
created by default to the right hand side

If I set the list box as width 150 and add a column

LSTProcessList.Columns.Add(New ColumnHeader)
LSTProcessList.Columns(0).Text = "Ref1"
LSTProcessList.Columns(0).Width = 150

Then I can grab the top of the column called Ref1, move it to the left and
there is a blank one to the right.

If the column doesn't fill the whole horizontal space of the listview
control, the header bar will fill the rest of the space.
Is there any way that I can have one single column that scrolls up and
down, but not left and right.

Set the column's width to the width of the listview's client size.
 
If your question is how to make the listview size fit the data
exactly, you can do this as follows

intLVWWidth = 0 <--- this will be the final width we want the
listview to be once we size the columns to the data.

for i = 0 to lstView.Columns.Count - 1
lstView.Columns(i).Width = -2 <--- this forces col to fit data
intLVWWidth += lstView.Columns(i).Width
next
intLVWWidth += SystemInformation.Border3DSize.Width * 2 +
SystemInformation.VerticalScrollBarWidth
lstView.Width = intLVWWidth

This will eliminate the space on the right and fit every thing
perfectly. A refinement is to be sure that the column heading is not
larger than any of the data. To do this, in the loop, you can look at
the lstView.Columns(i).Width = -1 value. That sizes the column to the
header. If it is greater than the data width, then use it.

Thanks goes to someone on this NG for sharing this with me. I thought
it was neat. Hope it is what you are looking for.

John
 
Aha....credit for my last post goes to Tim Wilson on the Window Froms
Control list. Thanks Tim!

John
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top