Skip to content
Loading
  • Laxmidhar Sahoo
    +1
    Your code is looking good .But in the foreach loop you may apply a if condition for checking the textbox value with g1.Cells["bar_kod"].Value
    +1
  • Sreekanth Reddy
    +1
    Please put debugger and check what value you are getting for the expression "Convert.ToInt32(g1.Cells["kolicina"].Value) + 1;" by using quick watch & Let us know here too.So that we can try on that way.
    because your code seems everything was right.
    Thank you.
    +1
  • Laxmidhar Sahoo
    +1
    There is a textbox In your statement of  if exist in datagrid value from textbox1 ( column name: bar_code) to increment cell
    +1
  • Sreekanth Reddy
    +1
    Yes, It will add based on the rows count of the datagridview1 rows.
    If it has 2 rows it'll add 2 & like that. 
    +1
  • Laxmidhar Sahoo
    +1
    1. foreach (DataGridViewRow g1 in dataGridView1.Rows)    
    2.                         {    
    3.     
    4.     
    5.                             g1.Cells["ukupno"].Value = (Convert.ToDouble(g1.Cells["kolicina"].Value) *              Convert.ToDouble(g1.Cells["cijena"].Value)).ToString("0.00");  
    6.                 if(g1.Cells["bar_kod"].Value == "your compare value")  
    7.                                g1.Cells["kolicina"].Value = Convert.ToInt32(g1.Cells["kolicina"].Value) + 1;  
    8.                         }  
    +1
  • Laxmidhar Sahoo
    +1
    the code in the loop place in try catch block .Give abreak point and display the line
    +1
  • 0
    Not solution
    0
  • 0
    Laxmidhar Sahoo
     
    I dont have textbox for this value.
     
    I post picture
    0
  • 0
    Laxmidhar Sahoo
     
    I try this but not work
     
    Error is
     
     warning CS0252: Possible unintended reference comparison; to get a value comparison, cast the left hand side to type 'string'

     
    1. foreach (DataGridViewRow g1 in dataGridView1.Rows)  
    2.                         {  
    3.   
    4.   
    5.                             g1.Cells["ukupno"].Value = (Convert.ToDouble(g1.Cells["kolicina"].Value) * Convert.ToDouble(g1.Cells["cijena"].Value)).ToString("0.00");  
    6.   
    7.                             if (g1.Cells["bar_kod"].Value == textBox1.Text.ToString())  
    8.                             {  
    9.                                 //if (g1.Cells["bar_kod"].Value == "your compare value")  
    10.   
    11.                                 g1.Cells["kolicina"].Value = Convert.ToInt32(g1.Cells["kolicina"].Value) + 1;  
    12.                             }  
    13.                         } 
     
    0
  • 0
    Break point
     
    Warning display result
     
    Severity Code Description Project File Line Suppression State
    Warning CS0252 Possible unintended reference comparison; to get a value comparison, cast the left hand side to type 'string'

     
    0
  • 0
    This is my code not answer
     
    Laxmidhar Sahoo
    • 482
    • 3.2k
    • 4.3k
    Nov 21 2018 9:52 PM
     
    0