We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
close icon

Problem with CurrentCell not changing

I have a Grid Control (non-databound) that I ocassionally reload the entire grid. Before reloading I execute the following code to clear out the data: gridControl1.Focus(); gridControl1.CurrentCell.MoveTo(-1, -1); gridControl1.ClearCells(GridRangeInfo.Table(), true); gridControl1.RowCount = 0; After reloading the data my CurrentCell is still set to the previous row that was selected before the above code was executed. I have trapped in the CurrentCellMoving event and it does get executed on the moveto method. Any ideas?

5 Replies

AD Administrator Syncfusion Team March 27, 2003 03:13 PM UTC

I tried this code in a button handler and things seemed to work as expected.
private void button1_Click(object sender, System.EventArgs e)
{
	gridControl1.Focus();
	gridControl1.CurrentCell.MoveTo(-1, -1);
	gridControl1.ClearCells(GridRangeInfo.Table(), true);
	gridControl1.RowCount = 0;

	MessageBox.Show("EmptyGrid");

	gridControl1.Focus();
	gridControl1.RowCount = 20;
}
You might use the Debug|Exceptions menu item to set Common Language Runtime exceptions to break into teh debugger to see if there is some type of exception being thrown that would interfere with this behavior. Also, when you perform this code, what is teh state of the grid at that point? Is this code being call from an event handler that might not expect the RowCount to change? If you can reproduce the behavior in a sample project, you can submit in a Direct Trac support incident, and we will take a look at it to see if we can spot what is going on.


AD Administrator Syncfusion Team March 27, 2003 06:17 PM UTC

The following exception is thrown when I do the moveto(-1,-1): System.ArgumentException: negative key at Syncfusion.Windows.Forms.Grid.GridIndexDictionary.OnValidate(Object key, Object value) at Syncfusion.Collections.TypedDictionaryBase.System.Collections.IDictionary.set_Item(Object key, Object value) at Syncfusion.Windows.Forms.Grid.GridIndexDictionary.set_Item(Int32 key, Object value) at Syncfusion.Windows.Forms.Grid.GridRowColSizeDictionary.set_Item(Int32 index, Int32 value) at Syncfusion.Windows.Forms.Grid.GridModelRowColSizeIndexer.SetSize(Int32 index, Int32 value) at Syncfusion.Windows.Forms.Grid.GridModelRowColSizeIndexer.SetRange(Int32 from, Int32 to, Int32[] values, Boolean discardUndo) catched at Syncfusion.Windows.Forms.Grid.GridModelRowColSizeIndexer.SetRange(Int32 from, Int32 to, Int32[] values, Boolean discardUndo) in :line 0 which does cause the move to not occur. So how do I get the current row to be unset or point to -1,-1 like when the grid is intialized. > I tried this code in a button handler and things seemed to work as expected. >
> private void button1_Click(object sender, System.EventArgs e)
> {
> 	gridControl1.Focus();
> 	gridControl1.CurrentCell.MoveTo(-1, -1);
> 	gridControl1.ClearCells(GridRangeInfo.Table(), true);
> 	gridControl1.RowCount = 0;
> 
> 	MessageBox.Show("EmptyGrid");
> 
> 	gridControl1.Focus();
> 	gridControl1.RowCount = 20;
> }
> 
> > You might use the Debug|Exceptions menu item to set Common Language Runtime exceptions to break into teh debugger to see if there is some type of exception being thrown that would interfere with this behavior. > > Also, when you perform this code, what is teh state of the grid at that point? Is this code being call from an event handler that might not expect the RowCount to change? > > If you can reproduce the behavior in a sample project, you can submit in a Direct Trac support incident, and we will take a look at it to see if we can spot what is going on.


AD Administrator Syncfusion Team March 27, 2003 11:16 PM UTC

Instead of MoveTo(-1, -1), try calling CurrentCell.Deactivate.


AD Administrator Syncfusion Team March 28, 2003 02:10 PM UTC

That was actually the first thing I tried but after calling deactivate the currentcell.rowindex does not change. It only seems to change the IsActive to false.


AD Administrator Syncfusion Team March 28, 2003 06:46 PM UTC

After Deactivate you can change the row and column index with CurrentCell.SetCurrentCellNoActivate Stefan

Loader.
Live Chat Icon For mobile
Up arrow icon