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. (Last updated on: November 16, 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Set focus to a GDBG Cell

Thread ID:





33464 Aug 20,2005 06:03 AM UTC Aug 22,2005 11:42 AM UTC WinForms 2
Tags: GridControl
Osden Pereira
Asked On August 20, 2005 06:03 AM UTC

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 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)
		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
private void t_Tick(object sender, EventArgs e)
	t.Tick -= new EventHandler(t_Tick);
	t = null;
	GridCurrentCell cc = this.gridDataBoundGrid1.CurrentCell;
	cc.MoveTo(cc.RowIndex, targetCol);

Osden Pereira
Replied On August 22, 2005 11:42 AM UTC

Thanks Clay.


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.

Please sign in to access our forum

This page will automatically be redirected to the sign-in page in 10 seconds.

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