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

 

 

 

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

     

     

  • 53790
    posted

    Hi,

    May be one possible solution is to change your code like this:


    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.DataSource = null;
         this.grdData.DataSource = dsData;
        }

    Please check it and send me a feedback.
    Regards

  • 469350
    Offline posted

    Hi,

    The grid responds to the notifications from the DataSource asynchronously. So what probably happens here is that when you clear the data set, the grid doesn't clear it's own rows immediately, it waits for the next paint message.

    When you access the Rows collection here, you are still accessing the original rows collection, because the grid has not updated itself, yet.

    This is a little odd, because I would think accessing the Rows collection indexer should be forcing the grid to update itself.

    But anyway, if I am right, you should be able to get this to work by simply refreshing the grid:

    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.Refresh()

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