私はSubItems
のListViewItem
をクリアして再追加しようとしています。テキストを消去せずにListViewItemのサブアイテムをクリアするには?
private void RefreshItem(ListViewItem item)
{
item.Text = accountNumber;
item.SubItems.Clear(); //in case there are any
item.SubItems.Add(name);
item.SubItems.Add(address);
item.SubItems.Add(phone);
item.SubItems.Add(workphone);
item.SubItems.Add(email);
item.SubItems.Add(idType);
item.SubItems.Add(idNumber);
item.SubItems.Add(idExpires);
...
}
しかし、サブ項目をクリアすることもTextをクリアします。
注:逆説的に、
SubItems
をクリアすることもText
をクリアしますが、SubItems
を追加することもText
を追加しません。
私は唯一のサブアイテムを更新するときに問題にも表示されます。
private void RefreshItem(ListViewItem item)
{
item.SubItems.Clear(); //in case there are any
item.SubItems.Add(location);
item.SubItems.Add(date);
item.SubItems.Add(cashier);
item.SubItems.Add(totalBuyAmount);
item.SubItems.Add(totalSellAmount);
item.SubItems.Add(currencyCode);
item.SubItems.Add(exchangeRate);
item.SubItems.Add(isVip);
...
}
は、どのように私はListViewItemのSubItemsをClearが、Textをクリアすることはできませんか?
あなたはローカル変数で 'Text'を保存することはできません、' SubItems'た後、再設定 'Text'をクリア?おそらく最も理想的な解決策ではありません。 –
なぜサブアイテムをクリアしたいのですが、それに関連するテキストは消去したくないのです。 – John
@ジョンあなたは間違っているかもしれないと思います。 'Text'は' ListItem'自体のテキストです。 ListItemはSubItemを持つことができます。私はListItem.SubItemsコレクションをクリアしたいが、ListItem.Textプロパティは残しておく。 –