show data in datagridview by selecting multiple values choosing fron checked listbox c#

  • Thread starter Thread starter Jitendra Gautam
  • Start date Start date
J

Jitendra Gautam

Guest
I want to show the data in datagridview by selecting multiple ids from checkedlistbox in c# .

the code is below which i used.if you have a solution, pls help me.




private void checkedListBox1_SelectedIndexChanged(object sender, EventArgs e)
{
if (checkedListBox1.CheckedItems.Count != 0)
{
string s = "";
for (int x = 0; x <= checkedListBox1.CheckedItems.Count - 1; x++)
{
s = s + "Checked Item " + (x + 1).ToString() + " = " + checkedListBox1.CheckedItems[x].ToString() + "\n";
string strCon = @"Data Source=intel-pc\ogi;Initial Catalog=purchase;User ID=sa;Password=pa$$w0rd";
string strSQL = "select S_No,description,unit,quantity,approx_price,discount,total_amount from indent_items where indent_no=" + checkedListBox1.CheckedItems[x].ToString() + " or indent_no = " + checkedListBox1.CheckedItems[x].ToString() + "";

SqlDataAdapter dataAdapter = new SqlDataAdapter(strSQL, strCon);
SqlCommandBuilder commandBuilder = new SqlCommandBuilder(dataAdapter);

// Populate a new data table and bind it to the BindingSource.
DataTable table = new DataTable();
table.Locale = System.Globalization.CultureInfo.InvariantCulture;
dataAdapter.Fill(table);
bindingSource1.DataSource = table;

dataGridView2.AutoResizeColumns(DataGridViewAutoSizeColumnsMode.AllCellsExceptHeader);

dataGridView2.ReadOnly = false;

dataGridView2.DataSource = bindingSource1;

}
MessageBox.Show(s);
}


thnxs & Regards

Jitendra Gautam

Continue reading...
 
Back
Top