Click here to Skip to main content
15,896,557 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
C#
void dgvcheckIn_CellContentClick(object sender, DataGridViewCellEventArgs e)
       {
           try
           {
               dgvcheckIn.Focus();
               DataGridViewRow drow = dgvcheckIn.CurrentRow;
               if (e.ColumnIndex == 0)
               {
                   if ((bool)drow.Cells[0].Value == false)
                   {
                       drow.Cells[0].Value = true;
                  }
                   if ((bool)drow.Cells[0].Value == true)
                   {
                      drow.Cells[0].Value = false;
                   }
                   btnAddToBills.Focus();
               }
              
           }
           catch (Exception ex)
           {

           }
       }



here i got an error The given DataRow is not in the current DataRowCollection, how an i avoid this error?

Thanks in advance for your rply...........
Posted
Updated 12-Aug-14 1:24am
v2
Comments
Herman<T>.Instance 12-Aug-14 6:29am    
In which event this code is placed? Is it the SelectedRow of the gridview? is drow null or does it hold data? What did you debug?
victowork 12-Aug-14 7:24am    
drow is not not null check d ques once again
Herman<T>.Instance 12-Aug-14 7:42am    
You are at DataCell level. I guess you must cast your DataGridViewRow
DataGridViewRow drow = (DataGridViewRow)e.Parent;
or something similar like
DataGridViewRow drow = dgvcheckin.Rows[e.Rowindex];
Kornfeld Eliyahu Peter 12-Aug-14 7:31am    
It's not clear where you exactly get that error...However, why do all that if statements? Just put simply false into drow.Cells[0].Value? It will happen anyway...

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900