![](/img/trans.png)
[英]how to add the values related to the items selected in checkedlistbox
[英]How to add value to checkedListBox items
是否可以向checkedListBox
項添加值和標題
checkedListBox1.Items.Insert(0,"title");
如何添加還有價值?
checkedListBox1.Items.Insert(0, new ListBoxItem("text", "value"));
嘗試設置DisplayMember和ValueMember屬性。 然后你可以像這樣傳遞一個匿名對象:
checkedListBox1.DisplayMember = "Text";
checkedListBox1.ValueMember = "Value";
checkedListBox1.Items.Insert(0, new { Text= "text", Value = "value"})
編輯 :
要回答下面的問題,您可以為項目創建一個類,如下所示:
public class MyListBoxItem
{
public string Text { get; set; }
public string Value { get; set; }
}
然后像這樣添加它們:
checkedListBox1.Items.Insert(0, new MyListBoxItem { Text = "text", Value = "value" });
然后你可以得到這樣的價值:
(checkedListBox1.Items[0] as MyListBoxItem).Value
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.