c# - Multiple if conditions in for loop -


my application searches through cells in datagridview particular string , sums corresponding value in adjacent cell decimal variable. in code below when take out nested if anotherstring condition, code runs perfectly. nested if condition not run when insert code. doing wrong?

             decimal amount = 0;              decimal sum = 0;             foreach (datagridviewrow row in datagridview1.rows)            {             (int index = 0; index < datagridview1.columncount - 1; index++)                   {                     datagridviewcell cell = row.cells[index];                    if (cell.value == dbnull.value || cell.value == null)                        continue;                     if (cell.value.tostring().contains("string"))                    {                        if (cell.value.tostring().contains("anotherstring"))                        {                            datagridviewcell next = row.cells[index + 1];                            string s4 = next.value.tostring();                            amount += decimal.parse(s4, numberstyles.currency, custom);                             textbox50.text = amount.tostring();                         }                          datagridviewcell nexter = row.cells[index + 1];                        string s5 = nexter.value.tostring();                        sum += decimal.parse(s5, numberstyles.currency, custom);                         textbox41.text = sum.tostring();                     } 

you potentially in inner if statement contains case sensitive. either want use tolower or if care case use proper case in check.

if (cell.value.tostring().tolower().contains("string")) {    if (cell.value.tostring().tolower().contains("anotherstring"))    {        datagridviewcell next = row.cells[index + 1];        string s4 = next.value.tostring();        amount += decimal.parse(s4, numberstyles.currency, custom);         textbox50.text = amount.tostring();     }      datagridviewcell nexter = row.cells[index + 1];    string s5 = nexter.value.tostring();    sum += decimal.parse(s5, numberstyles.currency, custom);     textbox41.text = sum.tostring();  } 

Comments

Popular posts from this blog

toolbar - How to add link to user registration inside toobar in admin joomla 3 custom component -

linux - disk space limitation when creating war file -