views:

38

answers:

3

I have this:

lvPalette.Columns.Add("Code", -2, HorizontalAlignment.Center);
lvPalette.Columns.Add("Attendu", -2, HorizontalAlignment.Center);
lvPalette.Columns.Add("Chargé", -2, HorizontalAlignment.Center);
lvPalette.Columns.Add("Validé", -2, HorizontalAlignment.Center);
lvPalette.Columns.Add("Description", -2, HorizontalAlignment.Center);

Which end up making the first column as large as the control itself instead to be just as large as the header text. Why is that?

I tried to set first column widt to 100, but then its the 2nd column that take all the space up to the control width.

EDIT:I think I figured why it does that. It seems that setting width to -2 force the header to take whole control width space avaible. So when first column is added, it is the only one existing, so it take the whole control space, then the others are added and set to correct size.

So question would be, how can I prevent it to do it?

A: 

Try calling the AutoResize method on each of the columns after you've added the columns to the listview.

TLiebe
Yeah I know that and its what I do to fix it, but that is not the question. I want to know why the default resizer is not working properly.
Wildhorn
A: 

I think I figured why it does that. It seems that setting width to -2 force the header to take whole control width space avaible. So when first column is added, it is the only one existing, so it take the whole control space, then the others are added and set to correct size.

So question would be, how can I prevent it to do it?

Wildhorn
You should edit your original question with this information, instead of posting an answer.
Tim Coker
A: 

It seems there is no way to prevent this behavior beside setting values.

I found a way with autorizing via header and fields then selecting the one that had the largest width, but it has the bad side that it force 3 resizes, which is not graphically nice.

Wildhorn