Hi!
[NET 2.0, VS 2005, XP SP2]
I need to resize the last column in my listview control so that there won´t
be horizontal scrollbar.
Lets first create lv and add some items:
listView1.View = View.Details;
listView1.Columns.Add("Col 1");
listView1.Columns[0].Width = 100;
listView1.Columns.Add("Col 2");
listView1.Columns[1].Width = 200;
listView1.HeaderStyle = ColumnHeaderStyle.Nonclickable;
listView1.Size = new Size(200,60);
for (int i = 0; i < 10; i++) {
listView1.Items.Add(i.ToString());
}
Now, without executing this you can see that lv is too small to hold the
items - both scrollbars will be added.
Vertical scrollbar is ok, but i don´t want the horizontal one.
So, lets add the following code:
int w = 0;
byte i = 0;
for (; i < (listView1.Columns.Count - 1); i++) {
w += listView1.Columns[i].Width;
}
if (listView1.Items != null && listView1.Items.Count 0) {
//int a = listView1.Items[0].Bounds.Height;
}
listView1.Columns[i].Width = listView1.ClientRectangle.Width - w;
By adding this, the last column will become narrow but not enough.
If i uncomment the last line - it works exactly as it should: the last
column will use all the remaining space that isn´t left by other columns and
the vertical scrollbar.
Here comes my question: why is this working? Is it safe to use this?
thx!
Kimmo