[英]C# How to add an item to a listview if the item exists but the subitem is different?
[英]C# How to get the subitem on a listview to stay on the same line as the item?
所以我有以下代碼:
listView1.Items.Add("Test");
ListViewItem testing = new ListViewItem();
testing.SubItems.Add("Test2");
listView.Items.Add(testing);
這是它產生的:
(來源: gyazo.com )
不確定為什么“ Test2”位於底部。
首先,兩個列表視圖都是相同的listView1和listView? 如果是,那么這里是答案:
listView1.Items.Add(“ Test”); 在編寫此代碼行時,您要在列表視圖中添加第一項,其中主項為“測試”,所有子項為空。
listView.Items.Add(測試); 完成此操作后,您將在列表視圖中添加第二個項目,其中主項目為Empty,第一個子項目為“ Test2”
要在帶子項的listView中添加一項,請嘗試以下操作:
ListViewItem testing = new ListViewItem();
testing.Text="Test";
testing.SubItems.Add("Test2");
listView.Items.Add(testing);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.