使用此代码:
Dictionary<int, String> PlatypusAccountsDict = PlatypusSetupData.getPlatypusAccountsForCustomer(kvp.Key);
foreach (KeyValuePair<int, string> entry in PlatypusAccountsDict) {
int PlatypusAccountNumber = entry.Key;
string PlatypusAccountName = entry.Value;
ListViewGroup PlatypusAccountGroup = new ListViewGroup(PlatypusAccountName, HorizontalAlignment.Left)
{
Tag = PlatypusAccountNumber,
Header = PlatypusAccountName
};
listViewCustomerDuckBillAccountsClients.Groups.Add(PlatypusAccountGroup);
. . .
...我可以逐步查看“条目”中的值,但没有将任何组添加到我的 ListView 中 - 在此代码运行后,它仍然像一只松鸦一样赤裸裸。我知道这个问题有三个可能的原因:1)我忘记了一个步骤。2) 来自太阳的巨大 EMP 破坏了某些东西,或 3) 我不知道的其他东西。
更新
在调用 Groups.Add(PlatypusAccountGroup) 之后添加此测试代码:
ListViewItem listViewItem1 = new ListViewItem(new string[] { "Banana", "a" }, -1, Color.Empty, Color.Yellow, null);
ListViewItem listViewItem2 = new ListViewItem(new string[] { "Cherry", "v" }, -1, Color.Empty, Color.Red, new Font("Microsoft Sans Serif", 8.25F, FontStyle.Regular, GraphicsUnit.Point, ((System.Byte)(0))));
ListViewItem listViewItem3 = new ListViewItem(new string[] { "Apple", "h" }, -1, Color.Empty, Color.Lime, null);
ListViewItem listViewItem4 = new ListViewItem(new string[] { "Pear", "y" }, -1, Color.Empty, Color.FromArgb(((System.Byte)(192)), ((System.Byte)(128)), ((System.Byte)(156))), null);
listViewItem1.Group = PlatypusAccountGroup;
listViewItem2.Group = PlatypusAccountGroup;
listViewItem3.Group = PlatypusAccountGroup;
listViewItem4.Group = PlatypusAccountGroup;
this.listViewPlatypusAccounts.Items.AddRange(new ListViewItem[] {listViewItem1,
listViewItem2,
listViewItem3,
listViewItem4});
...确实添加了我想要/期望的组,但没有在其下方添加这些水果项目。