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
440
DoubleClickRow , RowSelect and selected rows
posted

Hi,

I have a grid for which I've set DisplayLayout.Override.CellClickAction to RowSelect.

I use the DoubleClickRow event to clear the data of the grid, fill the grid with data and then I activate/select the first row:

        private void grdData_DoubleClickRow(object sender, Infragistics.Win.UltraWinGrid.DoubleClickRowEventArgs e)
        {
            this.dsData.Rows.Clear();

            for (int i = 0; i < 10; i++)
            {
                UltraDataRow rootRow = this.dsData.Rows.Add();
                rootRow["Column 0"] = "1";
                rootRow["Column 1"] = "1";
            }

            this.grdData.Rows[0].Activate();
            this.grdData.Rows[0].Selected = true;
            this.grdData.Selected.Rows.Clear();           
        }

The problem is that the originally selected row gets selected again after grdData_DoubleClickRow() has finished. So I end up with the first row being selected and activated, but also with the originally selected row as selected. So the end result is that two rows are selected instead of one.

When I select a row and use the KeyDown event (using the F5 key in my example), I don't have this issue:

        private void grdData_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.F5)
            {
                this.dsData.Rows.Clear();

                for (int i = 0; i < 10; i++)
                {
                    UltraDataRow rootRow = this.dsData.Rows.Add();
                    rootRow["Column 0"] = "1";
                    rootRow["Column 1"] = "1";
                }

                this.grdData.Rows[0].Activate();
                this.grdData.Rows[0].Selected = true;
                this.grdData.Selected.Rows.Clear();
            }
        }

 

What could be the problem here?

 

 

regards,

 

Roel van Bueren

 

 

 

Parents
No Data
Reply
  • 469350
    Offline posted

    Hi,

    Okay, I see the problem now. I think what's happening here is that the DoubleClick event is firing on the second MouseDown. But then the final MouseUp is going to re-select the row that the mouse is on.

    So the sequence of events for the Double-Click goes like this:

    MouseDown

    MouseUp

    MouseDown

    DoubleCilck event fires and row 0 in the grid is selected.

    MouseUp - causes the row the mouse is over to be selected.

    To verify this, I used the same code you have here posted here. So in the DoubleClickRow event, I cleared the datasource rows, and then did this:

                    this.grdData.Rows[0].Activate();
                    this.grdData.Rows[0].Selected = true;
                    this.grdData.Selected.Rows.Clear();

    Then I put some Debug.Writeline statement into the AfterSelectChange event so I can see what's getting selected.

    When I run the app and DoubleClick on a row 2 in my grid, I see this:

    Selected Row: 0

    No rows selected

    Selected Row: 2

    So the code is selecting row 0, then clearing the selection, and then row 2 (which the mouse is over) gets selected after all of that is done.

    So... the solution is pretty simple. You just have to create a delay so that your code which selects the first row happens after the event and the MouseUp have already completed. You can do that by using a BeginInvoke.

    So the code will look something like this:


            private void ultraGrid1_DoubleClickRow(object sender, Infragistics.Win.UltraWinGrid.DoubleClickRowEventArgs e)
            {
                this.dsData.Rows.Clear();

                    for (int i = 0; i < 10; i++)
                    {
                        UltraDataRow rootRow = this.dsData.Rows.Add();
                        rootRow["Column 0"] = "1";
                        rootRow["Column 1"] = "1";
                    }


                    this.BeginInvoke(new MethodInvoker(this.SelectFirstGridRow));
            }

            private void SelectFirstGridRow()
            {
                this.ultraGrid1.Rows[0].Activate();
                this.ultraGrid1.Selected.Rows.Clear();
                this.ultraGrid1.Rows[0].Selected = true;
            }

     

     

Children
No Data