Please find a sample code for your question.
Steps Followed:
* I've created a checked list box and datagrid.
* Created a datagridview
* populated both with sample data
* on the checkedListBox1_ItemCheck event method, i've used LINQ to filter the datatable content based on the item checked.
* added the result dataset back to the grid.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace WindowsFormsApplication2
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
DataTable dt1 = new DataTable();
private void Form1_Load(object sender, EventArgs e)
{
string[] checkListItems = new string[] { "Item1", "Item2", "Item3", "Item4", "Item5" };
checkedListBox1.DataSource = checkListItems;
dt1.Columns.Add("ItemName");
dt1.Columns.Add("ItemDescription");
dt1.Rows.Add(new Object[] { "Item1", "This is Item 1" });
dt1.Rows.Add(new Object[] { "Item2", "This is Item 2" });
dt1.Rows.Add(new Object[] { "Item3", "This is Item 3" });
dt1.Rows.Add(new Object[] { "Item4", "This is Item 4" });
dt1.Rows.Add(new Object[] { "Item5", "This is Item 5" });
dataGridView1.DataSource = dt1;
dataGridView1.Refresh();
}
private void checkedListBox1_ItemCheck(object sender, ItemCheckEventArgs e)
{
var res = (from dtrows in dt1.AsEnumerable()
where dtrows.Field<string>("ItemName") == checkedListBox1.SelectedItem.ToString()
select new {
itemName = dtrows.Field<string>("ItemName"),
itemDesc = dtrows.Field<string>("ItemDescription")
}).ToList();
dataGridView1.DataSource = res;
dataGridView1.Refresh();
}
}
}
Hope this helps.