Search code examples
c#winformsdevexpressxtragrid

How to maintain selected row of XtraGrid control


I'm developing an application of the xtragridview control in that application when i'll double click on row from the xtragridview that time one popup form opens . then the focus of the parent window changes & focus is assigned to the another form which is popup . and that time my selected row changes it's state & it focus/select the default 1st row from the xtrgridview. but i want to maintain the focused/selected row as it is if user changes the focus from one form to another pop up form.

Is there any solution on this solution? what properties of xtragridview control should i've to set for this problem?

thanxs.....


Solution

  • Generally, the approach you are using does not require you to write an additional code. The XtraGrid does not reset its FocusedRow if you open a form by doubleclicking a grid row. So, I would suggest that you determine the cause of this behavior. This can be done by using the following approach:

    1) handle the GridView's FocusedRowChanged event and set a breakpoint in it.

    2) reproduce the issue and check which code forces the gridView to focus the first row.

    This should give an idea on why this happens.

    Also, I would suggest that you review the How to create the PopupForm for editing rows in the GridView and automatically create editors based on the column editors. example where the required functionality is implemented.

    I think I know the cause of this problem. It appears because you are changing the DataView's RowFilter property. I think you want your editors to point to the clicked record. The best solution is to do not filter the DataView but to assign the BindingContext as it is done in the example above. Here is the code from it:

    public EditForm(Point location, GridColumnCollection columns, object dataSource, BindingContext context)
                : this() {
                StartPosition = FormStartPosition.Manual;
                Location = location;
                BindingContext = context;  // <<<<<<
                allowTrackValueChanges = false;
                this.dataSource = dataSource;
    ...
    }