如何仅对数据集C#VS 2008中存在的数据设置复选框列表复选框 [英] how to set checkedlistbox check ture only for data present in dataset C# VS 2008

查看:76
本文介绍了如何仅对数据集C#VS 2008中存在的数据设置复选框列表复选框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,
我的清单框有问题,任何人都可以帮助我,或者让我知道如何解决此问题..

我有一个包含工作的Checkedlistbox.
我想检查从数据集中分配给员工的工作,并且只检查那些工作是真的..
问题是当它检查第一个作业为真时,
它来自foreach循环并引发异常.
此枚举器绑定到的列表已被修改.枚举器只能在列表不变的情况下使用."
这是我写的代码,

Hello everyone,
I am having a problem with checkedlistbox, can anyone help me, or give me some idea what should i do to fix this thing..

I have a Checkedlistbox with jobs in it.
I want to check the jobs assigned to employees from dataset and check only those jobs true..
The problem is when it checks the 1st Job true,
it comes out of foreach loop and throws exception.
"List that this enumerator is bound to has been modified. An enumerator can only be used if the list does not change."
This is the code i have written,

string sSQL="select JOBNO from RentalVehicle";
dataset ds = munshi.executeDS(sSQL,"Jobs").Tables["Jobs"];

                    foreach(DataRow Erow in ds.Rows)	
		    {
                    int CLB_RowNo = 0;
                    string[] JNos = Erow["JOBNO"].ToString().Split(', ');	//Jobdetail(2010-0191, HWS-01, ISB-6,KAD2-2, MAINT-01, PMO-2011-0052)

                    string SelectedJob = "", AJob = "";
                    foreach (Object obj in CLB_JobNo.Items)	// Looping CLB_JobNo(CheckedListBox)
                    {
                        int i = 0;
                        SelectedJob = obj.ToString();
                        foreach (string part in JNos)
                        {
                            AJob = JNos[i].ToString();
                            if (SelectedJob == AJob)
                            {
                                CLB_JobNo.SetItemChecked(CLB_RowNo, true);
                            }
                            i++;
                        }
                        CLB_RowNo++;
                    }



感谢您的每一个答复..



Thanks for every reply..

推荐答案



您的内循环遍历不正确.

在innner循环中,您曾经使用过foreach,但是使用i(variable);访问项目;

如下修改内部循环代码.


Hi,

Your inner loop traversal is incorrect.

In innner loop you have used foreach but accessing item with i(variable);

Modify the inner loop code as below.


string sSQL="select JOBNO from RentalVehicle";
dataset ds = munshi.executeDS(sSQL,"Jobs").Tables["Jobs"];

foreach(DataRow Erow in ds.Rows)
{
   int CLB_RowNo = 0;
   string[] JNos = Erow["JOBNO"].ToString().Split(', ');
   //Jobdetail(2010-0191, HWS-01, ISB-6,KAD2-2, MAINT-01, PMO-2011-0052)

   string SelectedJob = "", AJob = "";
   foreach (Object obj in CLB_JobNo.Items) // Looping CLB_JobNo(CheckedListBox)
   {
        SelectedJob = obj.ToString();
        foreach (string part in JNos)
        {
            AJob = part.ToString();
            if (SelectedJob == AJob)
            {
                  CLB_JobNo.SetItemChecked(CLB_RowNo, true);
            }
         }
         CLB_RowNo++;

    }
}


这篇关于如何仅对数据集C#VS 2008中存在的数据设置复选框列表复选框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆