Reputation: 11
I have a column of four values (depending on number of attached screens on the users's computer). I am trying to use a ListView as I've found an example where I can grey out the unavailable screens.
However the list of four items is being shown in two columns like this:
Screen 1 Screen 3
Screen 2 Screen 4
I have tried changing the width of the column and the control, but without success.
WHY?
I was thinking that maybe the first column is a header column so have tried adding two columns and setting the first one's width to zero. But it's still the same.
lvScreens.Columns.Add("Col", 0, HorizontalAlignment.Center);
lvScreens.Columns[0].Width = lvScreens.Width - 4;
lvScreens.FullRowSelect = true;
for (int i = 0; i < 4; i++) // I'm limiting the LV to 4 rows
{
ListViewItem lvi = new ListViewItem("Screen " + (i + 1).ToString());
lvScreens.Items.Add(lvi);
if (i < Screen.AllScreens.Count())
{
lvScreens.Items[i].ForeColor = SystemColors.ControlText;
lvScreens.Items[i].Selected = true;
}
else
{
lvScreens.Items[i].ForeColor = SystemColors.GrayText;
lvScreens.Items[i].Selected = false;
}
}
Upvotes: 1
Views: 7088
Reputation: 21999
ListView
control in winforms is a wrapper over winapi listview control. This control intended to be used for windows file explorer and utilize easy switching between multiple views: two icons (big and small) views, list and details.
It seems you have it currently in wrong view (not sure which one, list?).
Screen 1 Screen 3
Screen 2 Screen 4
Simply set ListView.View to Details
mode to see classic ListView
with multiple column headers (for each column you have actually added).
[Col]
Screen 1
Screen 2
Screen 3
Screen 4
Upvotes: 5