[SOLVED] DGV Row Selection and Deletion

Answered Closed
0
0

Hi,

After selecting multiple rows in datagridview and mouse right-click in a row other that the last row selected to view the context menu, SelectedRows.Count is reset to zero (0) as the table-row-indicator moves to the row where I initiated the mouse right-click. Rows selected remain highlighted though. Code below fails and nothing is deleted. Must right-click  on the last row select. In WinForm, the table-row-indicator doesn’t change location after right-click

If I select non-contiguous rows, unselected row in deleted and selected row remains undeleted. Please see attached images.

In both instances, I am using this code:

if (dgv.SelectedRows.Count > 0)
{
    foreach (DataGridViewRow row in dgv.SelectedRows)
    {
        if (!row.IsNewRow)
        {
            dgv.Rows.Remove(row);
        }
    }
}

Am I missing something?

And please confirm. If a row is new (IsNewRow=true), RowHeaderMouseClick doesn't flag the row as selected and
SelectedRows.Count remains zero (0). Is that by design?

Thanks




  • You must to post comments
Best Answer
0
0

Hi Luca,

#4 is now fixed in 1.2.68.0

Thanks.

  • You must to post comments
0
0

I can’t reproduce 4 with my build hopefully it’s fixed and was related to the grid clearing the selection on the server and not updating the client when changing the focused cell.

/Luca

  • You must to post comments
0
0

The issues I mentioned are bugs, logged and fixed – I don’t know if deployed, have to check.

I didn’t see the problem at point 4, will log as well. Thank you for the steps.

Best,

Luca

 

  • You must to post comments
0
0

Hi Luca,

Thanks for your test app.

Sorry if I didn’t explain well what I want to drive at. I am now using your test app and made a list of the steps I did to see my point.

  1. Click any column in Row 9 (new row with + sign).
  2. Click “Display Selected Rows” button and it shows “Selected Row Count = 1”.
  3. Click RowHeader of the same row (Row 9).
  4. Click “Display Selected Rows” and it shows “Selected Row Count = 0”. To mark it as selected row, I must click any of the rows above and then click back to Row 9. Select Row Count is now equal to 1.

You said “The automatic new row is selected like any other row”. You are correct and that’s true if and only if I didn’t click any of the cells in Row 9 prior to clicking the RowHeader.

As regards to two issues you mentioned above, does it mean that there is no fix for that? WinForm handles multiple rows selection and deletion whether adjacent or non-adjacent rows using a context menu.

Actually, I resolved this deletion issue by inserting a checkbox as the first column in the grid and loop thru all the rows using a button and test the value of the checkbox. But users always look for a context menu (right-click) in a data-centric application. Just my opinion though.

Thanks.

  • You must to post comments
0
0

Hi Cris,

Two issues:

  • The wrong row is removed from the client when removing multiple rows because the index is adjusted and the client removes the absolute index.
  • Right clicking moves the focused cell without affecting the selection, however the server side clears the selected rows without updating the client. But it should leave the selection unchanged.

The automatic new row is selected like any other row. I just tried in the test associated with this issue (attached).

Best,

Luca

  • You must to post comments
Showing 5 results