curiouswebster
asked on
Trouble formatting columns width for a ListView
Hi,
I am trying to format the column widths for a ListView but it's not working. Is this a bug in Windows? I use C#.NET Framework 2.0.
The first two columns are very narrow and the third is very wide, taking up the remaining unused space.
Here's the code.
Thanks,
newbieweb
addColumns is true the first time I create the dialog.
listView.SuspendLayout();
if (addColumns)
{
// Create columns for the items and subitems.
listView.Columns.Add("#", (int)0.15 * listView.Width, HorizontalAlignment.Left);
listView.Columns.Add("Stre et", (int)0.55 * listView.Width, HorizontalAlignment.Left);
listView.Columns.Add("Comp lete In", (int)0.25 * listView.Width, HorizontalAlignment.Left);
ListViewItem item1 = new ListViewItem("0");
for (int ii = 0; ii < listView.Columns.Count; ii++)
{
listView.Columns[ii].Width = -2;
}
}
if (orderStatusList != null && orderStatusList.Count > 0)
{
foreach ( Order order in orderStatusList )
{
ListViewItem item1 = new ListViewItem(order.OrderNu m);
item1.SubItems.Add(order.S treet);
item1.SubItems.Add(order.C ompletionM inutes.ToS tring());
listView.Items.Add( item1 );
}
}
listView.ResumeLayout();
I am trying to format the column widths for a ListView but it's not working. Is this a bug in Windows? I use C#.NET Framework 2.0.
The first two columns are very narrow and the third is very wide, taking up the remaining unused space.
Here's the code.
Thanks,
newbieweb
addColumns is true the first time I create the dialog.
listView.SuspendLayout();
if (addColumns)
{
// Create columns for the items and subitems.
listView.Columns.Add("#", (int)0.15 * listView.Width, HorizontalAlignment.Left);
listView.Columns.Add("Stre
listView.Columns.Add("Comp
ListViewItem item1 = new ListViewItem("0");
for (int ii = 0; ii < listView.Columns.Count; ii++)
{
listView.Columns[ii].Width
}
}
if (orderStatusList != null && orderStatusList.Count > 0)
{
foreach ( Order order in orderStatusList )
{
ListViewItem item1 = new ListViewItem(order.OrderNu
item1.SubItems.Add(order.S
item1.SubItems.Add(order.C
listView.Items.Add( item1 );
}
}
listView.ResumeLayout();
ASKER
Would you be so kind as to provide me the code for this?
When you create the columns, which constructor do you use?
When you size them, how do you do that exactly?
Thanks,
newbieweb
When you create the columns, which constructor do you use?
When you size them, how do you do that exactly?
Thanks,
newbieweb
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
That was the trick!
Thanks,
newbieweb
Thanks,
newbieweb
I use a different approach, I create the columns at the Load event, and resize them at the form's Size event, so if you or the user change the size of the form, proportion is keeped.
Also you have to decrement a couple of pixels from the listView.Width ('cause of the margin) to avoid the horizontal bar to appear.