[英]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.我正在尝试使用 ListView,因为我找到了一个可以将不可用屏幕灰显的示例。
However the list of four items is being shown in two columns like this:但是,四个项目的列表显示在两列中,如下所示:
Screen 1 Screen 3屏幕 1 屏幕 3
Screen 2 Screen 4屏幕 2 屏幕 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 . winforms 中的ListView
控件是对winapi listview 控件的封装。 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.此控件旨在用于 Windows 文件资源管理器并利用多个视图之间的轻松切换:两个图标(大和小)视图、列表和详细信息。
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).只需将ListView.View设置为Details
模式即可查看具有多个列标题的经典ListView
(对于您实际添加的每一列)。
[Col]
Screen 1
Screen 2
Screen 3
Screen 4
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.