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

孤街浪徒 提交于 2021-01-20 12:40:33

问题


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

回答1:


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


来源:https://stackoverflow.com/questions/56238331/a-listview-with-only-one-column-is-showing-its-items-in-two-columns

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!