C# CheckListBox에 동적 값 설정 및 선택된 아이템 Value 값 가져오기
C#에서... CheckListBox에 값 설정하고...
선택되어진 Item의 value 값을 확인한다.
public partial class Form1 : Form
{
// Form 오픈시 기본값 설정
private void DataBindforForm()
{
DataSet ds = new DataSet();
ds = SelectItems(); // CheckListBox를 채울 아이템 가져오기
if (ds != null)
{
if (ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
{
foreach (DataRow dr in ds.Tables[0].Rows)
{
CheckBoxItem.Items.Add(new ListBoxItem(dr["Title"].ToString(), dr["Value"].ToString()));
}
}
}
}
private void clbCheckBoxItem_DoubleClick(object sender, EventArgs e)
{
foreach (ListBoxItem obj in CheckBoxItem.SelectedItems)
{
MessageBox.Show("더블 클릭 - " + obj.value.ToString()); ;
}
}
}
// ListBoxItem 객체
public class ListBoxItem
{
public string name { get; set; }
public string value { get; set; }
public ListBoxItem(string v_name, string v_value)
{
this.name = v_name;
this.value = v_value;
}
public override string ToString() { return this.name; }
}