我正在尝试获得子项工作的最简单的 Listview 示例。但是这段代码:
private void button1_Click(object sender, EventArgs e) {
listView1.Groups.Add(new ListViewGroup("Kannst du mich sehen?", HorizontalAlignment.Left));
string[] strArr = new string[4] { "uno", "dos", "twa", "quad" };
for (int i = 0; i < strArr.Length; i++)
{
ListViewItem lvi = new ListViewItem(strArr[i]);
listView1.Items.Add(lvi);
lvi.SubItems.Add("Ciao, Baby!");
listView1.Items[i].Group = listView1.Groups[0];
}
}
...不显示子项(“Ciao,Baby!”)。表明:
Kannst du mich sehen?
---------------------
uno dos twa quad
...但我希望它是:
Kannst du mich sehen?
---------------------
uno Ciao, Baby!
dos Ciao, Baby!
twa Ciao, Baby!
quad Ciao, Baby!
甚至更陌生(在我看来),我明白了:
Default
-------
uno dos twa quad uno dos twa quad
FIRST
-----
uno dos twa quad
...使用此代码:
private void button2_Click(object sender, EventArgs e) {
string[] strArrGroups = new string[3] { "FIRST", "SECOND", "THIRD" };
string[] strArrItems = new string[4] { "uno", "dos", "twa", "quad" };
for (int i = 0; i < strArrGroups.Length; i++)
{
listView1.Groups.Add(new ListViewGroup(strArrGroups[i], HorizontalAlignment.Left));
for (int j = 0; j < strArrItems.Length; j++) {
ListViewItem lvi = new ListViewItem(strArrItems[j]);
listView1.Items.Add(lvi);
lvi.SubItems.Add("Hasta la Vista, Mon Cherri!");
listView1.Items[j].Group = listView1.Groups[i];
}
}
}
更新
如果你问我,ListView 的 View 属性有点奇怪:
默认的“ LargeIcon ”设置与最初显示的一样(和 SmallIcon 具有相同的效果)。“ Detail ”只给了我组标题(没有项目)“ List ”给了我项目(一个在一行上,我想要),但没有组/标题“ Tile ”给我:
Kannst du mich sehen?
---------------------
uno dos
twa quad
...使用button1的代码和:
Default
---------------------
uno dos
twa quad
uno dos
twa quad
FIRST
---------------------
uno dos
twa quad
...使用 button2 的代码
任何一个:
1) I'm stupid
2) ListView is very counterintuitive
-or
3) Nobody ever wants to use the ListView the way I'm trying to use it...if that's the case, should I be using a different control instead?
~~~ 侧面(或底部)问题:由于我住在 StackOverflow 上,是否有可能成为双重公民,这样做有什么税收优惠吗?