Quantcast
Channel: Windows Forms Data Controls and Databinding forum
Viewing all articles
Browse latest Browse all 2535

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

$
0
0

 I want to show the data in datagridview by selecting multiple id's 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


Viewing all articles
Browse latest Browse all 2535

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>