mardi 12 janvier 2016

The best way to set all the datagrid cells of a row with the same value

I would like to improve this code whose goal is to work like the excel filters. If all of the checkboxes of the selected row are true, then the function (trigered by a button) set them all false, if they are all false, then they are set to true, and if at least one of them is false or true, then they all become true. But my code is only working when they are all true or false. The other condition is not allways working, this is because of the last part of the code which is not throwing the right result. The checkboxes are in the column 3 and from 7 untill 19 of a total of 21.

ublic void seleciona_check()
   {

    for (int i = 7; i < grid_lic.ColumnCount-1 ; i++)
       {
        for (int j = 7; j < grid_lic.ColumnCount - 1; j++)
         {

           if (grid_lic.CurrentRow.Cells[j].Value.ToString() == grid_lic.CurrentRow.Cells[i].Value.ToString())
           {
            if (grid_lic.CurrentRow.Cells[i].Value.ToString() == "True")
            {
             Convert.ToBoolean(grid_lic.CurrentRow.Cells[i].Value = false);

             Convert.ToBoolean(grid_lic.CurrentRow.Cells[3].Value = false);
          }

          else if (grid_lic.CurrentRow.Cells[i].Value.ToString() == "False")
          {
           Convert.ToBoolean(grid_lic.CurrentRow.Cells[i].Value = true);

           Convert.ToBoolean(grid_lic.CurrentRow.Cells[3].Value = true);
   }

    }
     }
       else if (grid_lic.CurrentRow.Cells[j].Value.ToString() != grid_lic.CurrentRow.Cells[i].Value.ToString())
        {
                      Convert.ToBoolean(grid_lic.CurrentRow.Cells[i].Value = true);
                           Convert.ToBoolean(grid_lic.CurrentRow.Cells[j].Value = true);
                           Convert.ToBoolean(grid_lic.CurrentRow.Cells[7].Value = true);
                           Convert.ToBoolean(grid_lic.CurrentRow.Cells[3].Value = true);
        }




Aucun commentaire:

Enregistrer un commentaire