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 Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Listview Column Width -1 Compact Framework

Status
Not open for further replies.

BoerPuillaert

Technical User
Aug 20, 2004
2
BE
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?
 
I forgot to mention, it works on the .NET framework but not on the .net compact framework.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top