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

how to programmatically activate a cell in a grid control

without user clicking on the cell? thanks in advance!

3 Replies

AD Administrator Syncfusion Team July 2, 2003 04:50 AM UTC

You can use code like Dim cc As GridCurrentCell = Me.grid.CurrentCell cc.MoveTo(1, 2, GridSetCurrentCellOptions.SetFocus) If you are doing this when the grid is hidden (like in Form_Load or from another tab that is active), you should also set: Me.grid.ForceCurrentCellMoveTo = True


JC jacky chen July 3, 2003 02:12 AM UTC

thanks clay, but it doesn't really work, what i really want is when user clicks on a cell, it activates not the currently clicked cell but another one that i specify in my code. i tried the line you gave, the cursor disappeared from the currently clicked cell but it doesn't go to the one specified in MoveTo method, and typing on keyboard doesn't produce anything on either cell. could you kindly explain to me what's exactly happening? thanks


AD Administrator Syncfusion Team July 3, 2003 07:36 AM UTC

You cannot call a CurrentCell.MoveTo if the grid is in the process of deactivating or activating a cell. (Sort of like calling a MoveTo from within a MoveTo - the grid does not know how to handle this.) I suspect this is what is going on at the point you called MoveTo. The grid was already in the process. If you want to do someting like this, you can handle MouseDown, remember the cell. And then handle MouseUp, checking to see if it is the same MouseDown cell, and if it is a cell you do not want to click. If it is, then call MoveTo at that point.
private int mouseDownRow = -1;
private int mouseDownCol = -1;
private void gridControl1_GridControlMouseDown(object sender, Syncfusion.Windows.Forms.CancelMouseEventArgs e)
{
	this.gridControl1.PointToRowCol(new Point(e.MouseEventArgs.X, e.MouseEventArgs.Y), out mouseDownRow, out mouseDownCol, -1);
}

private void gridControl1_GridControlMouseUp(object sender, Syncfusion.Windows.Forms.CancelMouseEventArgs e)
{
	int row;
	int col;
	if(	this.gridControl1.PointToRowCol(new Point(e.MouseEventArgs.X, e.MouseEventArgs.Y), out row, out col, -1)
		&& row == mouseDownRow && col == mouseDownCol)
	{
		//change the click from cell 2,2 to 1,1
		if(row == 2 && col == 2)
		{
			this.gridControl1.CurrentCell.MoveTo(1,1);
			//    and/or maybe 
			//this.gridControl1.ScrollCellInView(1,1);
		}
	}
	mouseDownRow = -1;
	mouseDownCol = -1;
}

Loader.
Live Chat Icon For mobile
Up arrow icon