Category / Section
How to handle the activating or deactivating the current cell exception in WinForms GridControl?
1 min read
Steps for handle the exception
When you try to add a row to the GridControl, it resets the CurrentCell that causes a problem at the middle of activating or deactivating the CurrentCell.
Solution
You can avoid this by working directly with the grid’s GridData object.
C#
//add the row this.gridControl1.Model.Data.RowCount += 1;
VB
'add the row Me.gridControl1.Model.Data.RowCount += 1
You can also achieve this by locking the CurrentCell before incrementing the RowCount and unlock after that.
C#
//lock and unlock the cell while add the row this.gridControl1.CurrentCell.Lock(); this.gridControl1.RowCount += 1; this.gridControl1.CurrentCell.Unlock();
VB
'lock and unlock the cell while add the row Me.gridControl1.CurrentCell.Lock() Me.gridControl1.RowCount += 1 Me.gridControl1.CurrentCell.Unlock()