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

How to set focus to a cell in a data grid

1)How to set focus to a cell in a data grid? 2) Is is possible to have a default value in the new row created with EnableAddNew = true. If possible can you give me the sample code to do so. Thanks in advance.

1 Reply

AD Administrator Syncfusion Team June 16, 2003 07:16 AM UTC

1) Use grid.CurrentCell.MoveTo to set the current cell to a particular row and column. If you are trying to do this from Form-Load, also set grid.ForceCurrentCellMoveTo = true; 2) In the grid, the default values come from GridDataBoundGrid.Model.ColStyles[col].CellValue. So, in your formload, if you have the DataTable.Columns[col].DefaultValue's, you could move them into the ColStyles. Here is a little sample showing how you might do it. But if you want to dynamically set the values without relying on the defaults in the DataTable, try handling CurrentCellMoved.
private void gridDataBoundGrid1_CurrentCellMoved(object sender, GridCurrentCellMovedEventArgs e)
{
	GridCurrentCell cc = this.gridDataBoundGrid1.CurrentCell;
	if(cc.RowIndex == this.gridDataBoundGrid1.Model.RowCount)
	{
        	this.gridDataBoundGrid1.Binder.BeginEdit();
		this.gridDataBoundGrid1[cc.RowIndex , 1].Text = "defaultcol1";
		this.gridDataBoundGrid1[cc.RowIndex  , 2].Text = "defaultcol2";
	}
}

Loader.
Live Chat Icon For mobile
Up arrow icon