[英]How To Retrieve Checkedlistbox Value From Database
我需要在C#中單擊“修改”按鈕時,將數據從datagridview獲取到清單列表框。
數據將在插入操作期間已經存儲在數據庫中,而更新時我需要將數據從數據庫中提取到checkedlistbox,並應檢查數據。
來自數據庫的數據應與checkedlistbox中的數據進行比較,如果兩者均相等,則應進行檢查。
string category = dgEntry.CurrentRow.Cells[8].Value.ToString();
string[] strCat = category.Split(',');
int length = strCat.Length;
for (int i = 0; i < length ; i++)
{
string fetch = strCat[i];
foreach (object item in clbEntry_IndividualItems.Items)
{
DataRowView row = item as DataRowView;
if (row[0].ToString() == strCat[i].ToString())
{
clbEntry_IndividualItems.SetItemChecked(i, true);
}
}
}
請幫我解決這個問題。
如果您的第一個檢查為真(作為您的評論),則可以添加第二個循環來檢查所有內容:
string category = dgEntry.CurrentRow.Cells[8].Value.ToString();
string[] strCat = category.Split(',');
int length = strCat.Length;
int _lenghth =clbEntry_IndividualItems.Items.count();
for (int j=0, j<_lenghth ,j++){
for (int i = 0; i < length ; i++)
{
string fetch = strCat[i];
foreach (object item in clbEntry_IndividualItems.Items)
{
DataRowView row = item as DataRowView;
if (row[j].ToString() == strCat[i].ToString())
{
clbEntry_IndividualItems.SetItemChecked(i, true);
}
}
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.