我剛剛如何在SQL數據綁定表到CheckBoxList的沒有壓力。我非常激動地分享它。 我手動添加他們...
SqlConnection conn = new SqlConnection();
SqlCommand cmd = new SqlCommand();
conn.ConnectionString = "Data Source=MICMIKE\\SQLEXPRESS;Initial Catalog=Enterprise;Integrated Security=True";
conn.Open();
string query = "Select Position from Position";// position column from position table
cmd.Connection = conn;
cmd.CommandText = query;
SqlDataReader dr = cmd.ExecuteReader();
while (dr.Read())
{
string myItem = dr["Position"].ToString();
checkedListBox1.Items.Add(myItem, true);//true means check the items. use false if you don't want to check the items or simply .....Items.Add(myItem);
}
要訪問checklistbox檢查的項目,使用
foreach(object item in Checkedlistbox1.CheckedItems)
{
string itemchecked = item.ToString();
MessageBox.Show(itemchecked);// This will show all the checked items in the checklistbox.
}
它是真正的工作。我剛剛拿到了。 我希望你喜歡它!
我已經在做這個。我來自WPF,我曾經將所有東西都綁定到屬性上,而我似乎無法向checkListBox添加綁定。「isChecked」屬性。我知道這個地產並不存在,所以我們怎麼能和它綁定呢?我只是想確保沒有隱藏的技巧可以讓我們做到這一點。 – FailedDev
DisplayMember綁定,但ValueMember不會!!!沒有意義。我用你的循環成功。謝謝 –
當然這不是__real雙向數據綁定。 – TaW