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.

How to set focus to a cell in a data grid

Thread ID:

Created:

Updated:

Platform:

Replies:

5027 Jun 16,2003 02:38 AM Jun 16,2003 03:16 AM Windows Forms 1
loading
Tags: GridControl
vamsi krishna
Asked On June 16, 2003 02:38 AM

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.

Administrator [Syncfusion]
Replied On June 16, 2003 03:16 AM

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";
	}
}

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.

;