简体   繁体   中英

A ListView with only one column is showing its items in two columns

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;
                }
            }

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM