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

Set focus to a GDBG Cell

Hi, I have a GDBG where i validate the data entered by the user. I validate the data in the RowLeave event. I want to move the focus to a particular cell to prompt the user to enter the missing data. following is the code: ---------------------------------------- private void libgrid_RowLeave(object sender, GridRowEventArgs e) { if(e.IsAddNew == true) { if (this.libgrid.DataSource.ToString() == "STRV_TravelClass") { //Check For selected Grade if (this.libgrid[e.RowIndex,1].Text.Trim() == "") { e.Cancel = true; MessageBox.Show(this,"Please Select Employee Grade.","Staff Travel - Library Data Check",MessageBoxButtons.OK,MessageBoxIcon.Warning); this.libgrid.ForceCurrentCellMoveTo = true; this.libgrid.CurrentCell.MoveTo(e.RowIndex,1,GridSetCurrentCellOptions.ForceRefresh); } } else if (this.libgrid.DataSource.ToString() == "STRV_TravelFares") { } else if (this.libgrid.DataSource.ToString() == "") { } } } ---------------------------------------- The above code does not seem to work. it displays the message box but does not move the focus to the first cell on the row.

2 Replies

AD Administrator Syncfusion Team August 20, 2005 09:15 AM UTC

The simplest way to do this is to let the RowLeave finish its Cancel work (as this point the focus back to the last editing cell), and then move the currentcell. If you do not, then the RowLeave will undo your call to CurrentCell.MoveTo. You can let RowLeave finish by using a Timer.
Timer t = null;
int targetCol = -1;
private void gridDataBoundGrid1_RowLeave(object sender, GridRowEventArgs e)
{
	if(ThereIsAProblem())
	{
		MessageBox.Show( "Don''t leave");
		e.Cancel = true;
		if(t == null)
		{
			t = new Timer();
			t.Interval = 30;
			t.Tick += new EventHandler(t_Tick);
		}
		targetCol = 3;//where you want to go
		t.Start();
	}
}
private void t_Tick(object sender, EventArgs e)
{
	t.Stop();
	t.Tick -= new EventHandler(t_Tick);
	t.Dispose();
	t = null;
	GridCurrentCell cc = this.gridDataBoundGrid1.CurrentCell;
	cc.MoveTo(cc.RowIndex, targetCol);
}


OP Osden Pereira August 22, 2005 11:42 AM UTC

Thanks Clay.

Loader.
Live Chat Icon For mobile
Up arrow icon