Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
1205
Retain Row Focus On New/Edited Row
posted

Using WinGrid AfterRowUpdate event  I’m updating each added row or edited after each row loses focus. Prior to updating the database, each row is checked for valid content. If a row fails the validation process I return to the grid for corrective revisions. My issue is returning to the row requiring revision. Instead of returning to the invalid row I return to the row I clicked on to lose focus. I thought I had the problem solved with the below code but it’s still returning to the last row I clicked on.

 

ugPTOEmployeeActiveRow = ugPTOEmployee.ActiveRow.Index;

// returns new or edited index correctly

 

 

errorString = EditEmployeeRowInput.EditRow(BEL_Employee);

 

if(errorString.Length != 0)

   {

    MessageBox.Show(errorString);

    ugPTOEmployee.Rows[ugPTOEmployeeActiveRow].Activate(); // ignores this index

    return;

   }

For example, this command ugPTOEmployee.Rows[12].Activate(); works on a button click event, but I’m missing something in getting to work after inserting/editing or a row.

It’s been awhile and I recall reading on the Forum there is a property that can be set to prevent the new/edited row from losing focus. Something about cancel or exit, but I was unable to relocate any reference to the specific post.

Thanks for taking a look at this and will appreciate your feedback.

  • 18495
    Suggested Answer
    posted

    Hello,

    Thank you for contacting Infragistics.

    Your call to UltraGridRow.Activate() is actually working properly.  The issue is that the grid is then proceeding to make the other row active.  You can use an approach similar to the following code to get the behavior you want.

    public partial class Form1 : Form
    {
    	private UltraGridRow lastActiveRow;
    	private bool retainFocus;
    
    	public Form1()
    	{
    		InitializeComponent();
    		this.retainFocus = false;
    	}
    
    	private void ultraGrid1_AfterRowUpdate(object sender, RowEventArgs e)
    	{
    		if (e.Row.Index == 2)
    		{
    			this.retainFocus = true;
    		}
    	}
    
    	private void ultraGrid1_AfterRowActivate(object sender, EventArgs e)
    	{
    		if (this.retainFocus)
    		{
    			this.retainFocus = false;
    			ultraGrid1.ActiveRow = lastActiveRow;
    		}
    		else
    		{
    			this.lastActiveRow = ultraGrid1.ActiveRow;
    		}
    	}
    }