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

Simulate a mouse click in a cell

How can I simulate a mouse click in a cell?
The Background: I have two grid controls in an form. I want to programmatically switch the focused cell from one grid to the other.


5 Replies

AG Andreas Gfeller April 30, 2008 11:47 AM UTC

I've attached a small sample project: Select a cell in one of the grids and move the cells with the keyborads arrow keys.

When reaching the upper or lower border of a grid, the focus switches to the other grid control.

But there is a problem: When the focus changes, the grid who lost the focus, still shows a dotted frame around the cell. This dotted frame does not appear when you change between the grids by mouse clicks.

How do I avoid this dotted frame?



TestApplication.zip


AG Andreas Gfeller May 6, 2008 07:31 AM UTC

No ideas?



AD Administrator Syncfusion Team May 13, 2008 06:20 AM UTC


Hi Andress,

Sorry for delay in replying.

There is a property that sets when the border around the currentcell is shown. Its called ShowCurrentCellBorderBehavior. Depending upon this setting, you can can see a border around the current cell when the grid has focus. You can set HideAlways before the CurrentCell is moved to next Grid and set WhenGridActive when the focus is back to the CurrentGrid. Please refer the modified code for more details.


private void gridControl2_CurrentCellKeyDown(object sender, KeyEventArgs e)
{
GridControl grid = sender as GridControl;
if (grid == null)
return;

int row = grid.CurrentCell.RowIndex;
int col = grid.CurrentCell.ColIndex;

switch (e.KeyCode)
{
case Keys.Up:
if (row > 1)
--row;
else
{
this.gridControl1.ShowCurrentCellBorderBehavior = GridShowCurrentCellBorder.WhenGridActive;
this.gridControl2.ShowCurrentCellBorderBehavior = GridShowCurrentCellBorder.HideAlways;
gridControl1.CurrentCell.MoveTo(gridControl1.RowCount, col, GridSetCurrentCellOptions.ScrollInView);
gridControl1.Focus();

}
break;

case Keys.Down:
if (row < grid.RowCount)
++row;
break;

case Keys.Left:
if (col > 1)
--col;
break;

case Keys.Right:
case Keys.Tab:
if (col < grid.ColCount)
++col;
break;

default: return;
} // switch
grid.CurrentCell.MoveTo(row, col, GridSetCurrentCellOptions.ScrollInView);
e.Handled = true;
}

private void gridControl1_CurrentCellKeyDown(object sender, KeyEventArgs e)
{
GridControl grid = sender as GridControl;
if (grid == null)
return;

int row = grid.CurrentCell.RowIndex;
int col = grid.CurrentCell.ColIndex;

switch (e.KeyCode)
{
case Keys.Up:
if (row > 1)
--row;
break;

case Keys.Down:
if (row < grid.RowCount)
++row;
else
{
this.gridControl1.ShowCurrentCellBorderBehavior = GridShowCurrentCellBorder.HideAlways;
this.gridControl2.ShowCurrentCellBorderBehavior = GridShowCurrentCellBorder.WhenGridActive;
gridControl2.CurrentCell.MoveTo(1, col, GridSetCurrentCellOptions.ScrollInView);
gridControl2.Focus();
}
break;

case Keys.Left:
if (col > 1)
--col;
break;

case Keys.Right:
case Keys.Tab:
if (col < grid.ColCount)
++col;
break;

default: return;
} // switch
grid.CurrentCell.MoveTo(row, col, GridSetCurrentCellOptions.ScrollInView);
e.Handled = true;
}


Please refer the sample in the below link that illustrates the above.

http://websamples.syncfusion.com/samples/Grid.Windows/F73291B/main.htm

Please let me know if this helps.

Regards,
Asem.




AG Andreas Gfeller May 13, 2008 12:14 PM UTC

Thank you Asem. That works perfect!



AD Administrator Syncfusion Team May 13, 2008 02:35 PM UTC

Hi Andreas,

Thanks for the update.

Regards,
Asem.


Loader.
Live Chat Icon For mobile
Up arrow icon