ahmed elbarbary

ahmed elbarbary

  • NA
  • 1.6k
  • 277.9k

How to print selected checkbox in datagridview and in case n

Mar 11 2018 5:01 PM
Actually I need to print records have checkbox checked = true inside datagridview
 
And if no any record checkbox checked meaning = false checked print all
 
I need to do that under button print .
 
No need to go inside code details I need only to implement only pseudo code below :
 
pseudo code
  1. if(any records checked checkbox = true)  
  2. print checked only in datagridview  
  3. else  
  4. print all in datagridview(in case no any checkbox checked inside grid)  
my current code print all :
  1. private void btnPrint_Click(object sender, EventArgs e)         
  2. {  
  3.     for (int i = 0; i < Grid.Rows.Count; i++)        
  4.     {  
  5.         if (string.IsNullOrEmpty(Convert.ToString(Grid.Rows[i].Cells["ItemCode"].Value))) return;  
  6.         Dictionary<string, string> Formulas = new Dictionary<string, string>();  
  7.         Formulas.Add("ImgFlds", BarcodePath);    
  8.         for (int x = 0; x < 4; x++)  
  9.         {  
  10.             string formula = "";  
  11.             int fieldVal = 0;  
  12.             if (x == 0)  
  13.             {  
  14.                 formula = "lefttopcap";  
  15.                 fieldVal = lefttopcap;  
  16.             }  
  17.             else if (x == 1)  
  18.             {  
  19.                 formula = "righttopcap";  
  20.                 fieldVal = righttopcap;  
  21.             }  
  22.             else if (x == 2)  
  23.             {  
  24.                 formula = "leftbottomcap";    
  25.                 fieldVal = leftbottomcap;  
  26.             }  
  27.             else if (x == 3)  
  28.             {  
  29.                 formula = "rightbottomcap";  
  30.                 fieldVal = rightbottomcap;  
  31.             }  
  32.             switch (fieldVal)  
  33.             {  
  34.                 case 1:  
  35.                     break;  
  36.                 case 2:  
  37.                     Formulas.Add(formula, Convert.ToString(Grid.Rows[i].Cells["CompanyName"].Value));  
  38.                     break;  
  39.                 case 3:  
  40.                     Formulas.Add(formula, Convert.ToString(Grid.Rows[i].Cells["BranchName"].Value));  
  41.                     break;  
  42.                 case 4:  
  43.                     Formulas.Add(formula, Convert.ToString(Grid.Rows[i].Cells["ItemLatName"].Value));  
  44.                     break;  
  45.                 case 5:  
  46.                     Formulas.Add(formula, Convert.ToString(Grid.Rows[i].Cells["ItemAraName"].Value));  
  47.                     break;  
  48.                 case 6:  
  49.                     Formulas.Add(formula, Convert.ToString(Grid.Rows[i].Cells["SelPrice1"].Value));  
  50.                     break;  
  51.                 default:  
  52.                     break;  
  53.             }  
  54.         }  
  55.         string sql = "select * from Branches where 1=1 ";  
  56.         int z = !string.IsNullOrEmpty(Convert.ToString(Grid.Rows[i].Cells["ItemCount"].Value)) ? Convert.ToInt32(Convert.ToString(Grid.Rows[i].Cells["ItemCount"].Value)) : 1;  
  57.         Reporting.PrinterName = cmbPrinterType.Text;     
  58.         Reporting.PrintType = PrintTypes.Print;    
  59.         CreateBarcode(Convert.ToString(Grid.Rows[i].Cells["code"].Value).Trim());    
  60.         picItem.Image.Save(BarcodePath);    
  61.         Reporting.ShowReport("BarcodePrinting.rpt", sql, Formulas, z);  
  62.     }  
  63. }  
to get checked checkbox in data gridview as following
  1. bool isSelected = Convert.ToBoolean(Grid.Rows[i].Cells["SelectedPrint"].Value); if (isSelected) { }  

Answers (1)