开发者

How to maintain selected row of XtraGrid control

开发者 https://www.devze.com 2023-02-21 06:00 出处:网络
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 focusof the parent window

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 fo开发者_运维问答cus/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.....


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


Mehod 1:

In the double click event handler just mention

return;

after all processes (Opening of another form etc.) are done.

After understanding your question better, I suggest to try method 2 I hope it surely works.

Method 2:

First record the current selected index before it opens another form or dialog ..

int index = datagridview.SelectedRows[0].Index;  //or xdatagrid.SelectedRows[0].Index;**

Then after completion of form opening or other procedure add the following line

datagridview.Rows[index].Selected = true; //or xdatagrid.Rows[index].Selected = true;**

**N.B.: I have never used xdatagrid, but suggesting the solutions depending on my datagridview experience.


I use

 GridView view = (GridView) sender;
 Point pt = view.GridControl.PointToClient(Control.MousePosition);
 var info = DoRowDoubleClick(view, pt);

when DoRowDoubleClick is:

 private static GridHitInfo DoRowDoubleClick(GridView view, Point pt) {

            GridHitInfo info = view.CalcHitInfo(pt);

            if (info.InRow || info.InRowCell){

                string colCaption = info.Column == null ? "N/A" : info.Column.GetCaption();

                MessageBox.Show(string.Format("DoubleClick on row: {0}, column: {1}.", info.RowHandle, colCaption));
                return info;
            }
            return null;
        }
0

精彩评论

暂无评论...
验证码 换一张
取 消