繁体   English   中英

如何从数据库中检索Checkedlistbox值

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM