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.
Unfortunately, activation email could not send to your email. Please try again.

Simulate a mouse click in a cell

Thread ID:

Created:

Updated:

Platform:

Replies:

73291 Apr 29,2008 11:16 AM May 13,2008 10:35 AM Windows Forms 5
loading
Tags: GridControl
Andreas Gfeller
Asked On April 29, 2008 11:16 AM

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.


Andreas Gfeller
Replied On April 30, 2008 07:47 AM

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

Andreas Gfeller
Replied On May 6, 2008 03:31 AM

No ideas?


Administrator [Syncfusion]
Replied On May 13, 2008 02:20 AM


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.



Andreas Gfeller
Replied On May 13, 2008 08:14 AM

Thank you Asem. That works perfect!


Administrator [Syncfusion]
Replied On May 13, 2008 10:35 AM

Hi Andreas,

Thanks for the update.

Regards,
Asem.


CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.

;