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

Cell Click Event ?

I have a form that does certain things based on which col the user clicks in. I have this code in the grd.cellclick event. I just noticed today that this event doesnt seem to happen if the user selects a range in a col. Is there an event i can use that will allow me to set up some code whether they click a single cell in a col or select a range of cells in a col?

4 Replies

AD Administrator Syncfusion Team March 15, 2005 04:19 PM UTC

The cell click event is only raised if you mousedown and mouseup in the same cell. If you want to catch mousing down/up in possibly different rows, but the same column, then you can catch both events, and remember the mousedown column and test for it in the mouse up event.
private int mouseDownCol = -1;
private void gridControl1_MouseDown(object sender, MouseEventArgs e)
{
	int row;
	int col;
	Point pt = new Point(e.X, e.Y);
	if(this.gridControl1.PointToRowCol(pt, out row, out col))
		this.mouseDownCol = col;

}
private void gridControl1_MouseUp(object sender, MouseEventArgs e)
{
	int row;
	int col;
	Point pt = new Point(e.X, e.Y);
	if(this.gridControl1.PointToRowCol(pt, out row, out col)
		&& col == this.mouseDownCol)
	{
		Console.WriteLine("MouseUp/Down Column");
	}
	this.mouseDownCol = -1;
}


AD Administrator Syncfusion Team March 15, 2005 04:50 PM UTC

That works for clicks but our users can also click one cell then use the arrow keys to move to another col and then select a range of cells with the arrow key. The mouseup and down doesnt work for that. I forgot to mention that. What im trying to do is this. I have one of your currencytextbox controls on a form with a grid. Depending on what col the user might click i update the data in the currencytextbox control and then it remembers that data so when they click another col and them move back it will put the data back the way it was for that col. So if the value of the currencytextbox control for col three is 3.35 and four is 5.55 then each time they click one of those cols it changes my currencytextbox control with the saved value whatever it may be. So everytime they click a new col i need to update that data. So is there something that will work no matter how a cell or range of cells gets selected in a certain col?


AD Administrator Syncfusion Team March 15, 2005 05:27 PM UTC

Try using the CurrentCellMoved event to catch moving the currentcell with the keyboard or with clicking. You can use the properties, grid.CurrentCell.MoveToColIndex and grid.CurrenCell.MoveFromColIndex, to see where you are and where you came from. But as far as catching mousing down on one column and mousing up on another column, I think you will still need to use something like the previous suggestion to handle this. It is teh simplest way that I know to do it.


AD Administrator Syncfusion Team March 15, 2005 07:03 PM UTC

Thanks. Works fine in the currentcellmoved event. I didnt have to put anything in the mouseup or down events. No matter how i move either by clicking a cell or dragging a range with the mouse or arrowing all over with the arrow keys it works no matter how i do it. Thanks again.

Loader.
Live Chat Icon For mobile
Up arrow icon