Mahmoud Mousaa

Mahmoud Mousaa

  • NA
  • 110
  • 721

how retrieve data from checkedlistbox selected and show data in datagr

Aug 29 2020 8:03 AM

I use these code to retrieve data from checkedlistbox selected and show data in datagrideview

problem query retrieve data one checkedlistbox selected not multi checkedlistbox selected I want to retrieve data in datagrideview with multi checkedlistbox selected 

  1. string s = "";  
  2. int x;  
  3. for (x = 0; x <= checkedListBox1.CheckedItems.Count - 1; x++)  
  4. {
  5.     s = "'" + checkedListBox1.CheckedItems[x].ToString() + "',";  
  6. }  
  7. s = s.Substring(0, s.Length - 1);  
  8. con = new SqlConnection(cs.DBConn);  
  9. con.Open();
  10. cmd = new SqlCommand("select id,'',raqam,name_sender,country1,country2,tel1,tel2,title,detalis,n_number,price,ship,total,name from pos where country2 IN("+s+") order by id asc ", con);  
  11.   
  12. rdr = cmd.ExecuteReader(CommandBehavior.CloseConnection);  
  13.   
  14. bunifuCustomDataGrid1.Rows.Clear();  
  15. while (rdr.Read() == true)  
  16. { 
  17.     bunifuCustomDataGrid1.Rows.Add(rdr[0], rdr[1], rdr[2], rdr[3], rdr[4], rdr[5], rdr[6], rdr[7], rdr[8], rdr[9], rdr[10], rdr[11], rdr[12], rdr[13], rdr[14]);  
  18.     bunifuCustomDataGrid1.Rows.OfType().Last().Selected = true;  
  19.     bunifuCustomDataGrid1.CurrentCell = bunifuCustomDataGrid1.Rows[bunifuCustomDataGrid1.Rows.Count - 1].Cells[1]; 
  20. }  
  21. con.Close();

Answers (1)