简体   繁体   中英

How To set Data In DataGridView by multiple selection of checkedListBox?

I have a iList in Which All Student Is there named as AllStudent i have 4 checkedListBox I want to filter grid data according to checkedlistbox checked items 我想要那个

 try
            {

                List<lclsItemShdule> li = new List<lclsItemShdule>();
                List<lclsItemShdule> li2 = new List<lclsItemShdule>();
                foreach (clsMylist item in clbClass.CheckedItems)
                {
                    li.AddRange(ItemScheduleDetail.Where(w => w.ClassId ==   item.ItemData).ToList());
                }

                li2.AddRange(li);
                li.Clear();
                foreach (clsMylist item in clbMedium.CheckedItems)
                {
                    li.AddRange(li2.Where(w => w.MediumId == item.ItemData).ToList());
                }
                li2.Clear();
                li2.AddRange(li);
                li.Clear();
                foreach (clsMylist item in clbStream.CheckedItems)
                {
                    li.AddRange(li2.Where(w => w.StreamId == item.ItemData).ToList());
                }
                li2.Clear();
                li2.AddRange(li);
                li.Clear();
                foreach (clsMylist item in clbShift.CheckedItems)
                {
                    li.AddRange(li2.Where(w => w.ShiftId == item.ItemData).ToList());
                }
                li2.Clear();
                li2.AddRange(li);

                dgvItemSchedule.DataSource = null;
                dgvItemSchedule.DataSource = li2;

            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }

Do it like this:

((DataTable)DataGridViews.DataSource).DefaultView.RowFilter =colmNameHere " like '%" + filterTextHere + "%'";

For this SO question colmNameHere like Class,Medium,Section and filterTextHere like Hostel,Primary,Hindi like wise.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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