G
Guest
Hi,
I have a datareader filling a listview, after that I want to set my listview
column width to the largest subitem in the column. You could do that by
setting width to -1.
I already found out about a bug that you could not set -1 by the columns.add
method
(http://support.microsoft.com/default.aspx?scid=kb;en-us;316572)
But it won't work like they descripe there either.
CODE
private void Form1_Load(object sender, System.EventArgs e)
{ ListViewItem item = new ListViewItem();
listView1.View = View.Details;
item.Text = "This is Item 1";
item.SubItems.Add("This is subitem 1 for item 1");
item.SubItems.Add("This is subitem 2 for item 1");
listView1.Items.Add(item);
ListViewItem item1 = new ListViewItem();
item1.Text = "This is Item 2";
item1.SubItems.Add("This is subitem 1 for item 2");
item1.SubItems.Add("This is subitem 2 for item 2");
listView1.Items.Add(item1);
listView1.Columns.Add("Column 1",-1, HorizontalAlignment.Left);
listView1.Columns.Add("Column 2", -2, HorizontalAlignment.Left);
listView1.Columns.Add("Column 3", -1, HorizontalAlignment.Left);
listView1.Columns[0].Width = -1;
}
So in the add method it will not work but
listView1.Columns[0].Width = -1;
should set column[0].width to the largest subitem in the column ... but it
doesn't...
Can anyone tell me how I can solve this?
(it works fine on the .NET framework, not on the .NET compact framework)
I have a datareader filling a listview, after that I want to set my listview
column width to the largest subitem in the column. You could do that by
setting width to -1.
I already found out about a bug that you could not set -1 by the columns.add
method
(http://support.microsoft.com/default.aspx?scid=kb;en-us;316572)
But it won't work like they descripe there either.
CODE
private void Form1_Load(object sender, System.EventArgs e)
{ ListViewItem item = new ListViewItem();
listView1.View = View.Details;
item.Text = "This is Item 1";
item.SubItems.Add("This is subitem 1 for item 1");
item.SubItems.Add("This is subitem 2 for item 1");
listView1.Items.Add(item);
ListViewItem item1 = new ListViewItem();
item1.Text = "This is Item 2";
item1.SubItems.Add("This is subitem 1 for item 2");
item1.SubItems.Add("This is subitem 2 for item 2");
listView1.Items.Add(item1);
listView1.Columns.Add("Column 1",-1, HorizontalAlignment.Left);
listView1.Columns.Add("Column 2", -2, HorizontalAlignment.Left);
listView1.Columns.Add("Column 3", -1, HorizontalAlignment.Left);
listView1.Columns[0].Width = -1;
}
So in the add method it will not work but
listView1.Columns[0].Width = -1;
should set column[0].width to the largest subitem in the column ... but it
doesn't...
Can anyone tell me how I can solve this?
(it works fine on the .NET framework, not on the .NET compact framework)