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

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
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)<br/>
{<br/>
if (checkedListBox1.CheckedItems.Count != 0)<br/>
{<br/>
string s = "";<br/>
for (int x = 0; x <= checkedListBox1.CheckedItems.Count - 1; x++)<br/>
{<br/>
s = s + "Checked Item " + (x + 1).ToString() + " = " + checkedListBox1.CheckedItems[x].ToString() + "n";<br/>
string strCon = @"Data Source=intel-pcogi;Initial Catalog=purchase;User ID=sa;Password=pa$$w0rd";<br/>
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() + "";<br/>
<br/>
SqlDataAdapter dataAdapter = new SqlDataAdapter(strSQL, strCon);<br/>
SqlCommandBuilder commandBuilder = new SqlCommandBuilder(dataAdapter);<br/>
<br/>
// Populate a new data table and bind it to the BindingSource.<br/>
DataTable table = new DataTable();<br/>
table.Locale = System.Globalization.CultureInfo.InvariantCulture;<br/>
dataAdapter.Fill(table);<br/>
bindingSource1.DataSource = table;<br/>
<br/>
dataGridView2.AutoResizeColumns(DataGridViewAutoSizeColumnsMode.AllCellsExceptHeader);<br/>
<br/>
dataGridView2.ReadOnly = false;<br/>
<br/>
dataGridView2.DataSource = bindingSource1;<br/>
<br/>
}<br/>
MessageBox.Show(s);<br/>
}<br/>


thnxs & Regards
Jitendra Gautam

View the full article
 
Back
Top