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.
Syncfusion Feedback

Set focus to a GDBG Cell

Thread ID:

Created:

Updated:

Platform:

Replies:

33464 Aug 20,2005 02:03 AM Aug 22,2005 07:42 AM Windows Forms 2
loading
Tags: GridControl
Osden Pereira
Asked On August 20, 2005 02:03 AM

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.

Administrator [Syncfusion]
Replied On August 20, 2005 05:15 AM

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

Osden Pereira
Replied On August 22, 2005 07:42 AM

Thanks Clay.

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.

Warning Icon 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.Close Icon

;