Skip to content

DataGridView row selection bug. #555

Closed

Description

@itg-assistant

Marian asked 2017-01-19 23:51:08 UTC

Hello,

I think I found a bug regarding the DataGridViewRow.Selected property. It appears that changing the grid DataSource and immediately setting the Selected property of a row has no effect (at least within the CellClicked event). It seems to always select the first row of the grid.

I've attached a project showing the issue.

Activity

  1. itg-assistant commented on Jun 12, 2026

    @itg-assistant
    Author

    Frank (ITG) answered 2017-01-21 11:40:27 UTC

    Thanks Marian !

    I have logged the bug as WJ-7956 and we will inform you when it is fixed.

    Best regards
    Frank

  2. added
    BugSomething is broken or behaving unexpectedly.
    on Jun 12, 2026
  3. itg-assistant commented on Jun 12, 2026

    @itg-assistant
    Author

    Frank (ITG) answered 2017-01-22 21:12:40 UTC

    Hi Marian,

    we have checked in more detail and found that in fact it´s not a bug.

    When changing the data source the focus cell is reset which causes the selection to be cleared. Works the same in WinForms. In fact in WinForms it's impossible to change the selected rows right after changing the data source.

    With Wisej it is possible thanks to its asynchronous nature. Change the sample code to:

    BeginInvoke(newAction(() =>

    {

    // Restore selection.

    foreach (DataGridViewRow row inthis.dataGridView1.Rows)

    {

    if (selectedItems.Contains(row.DataBoundItem))

    {

    row.Selected = true;

    Debug.WriteLine($"{row.DataBoundItem} selected.");

    }

    else

    {

    row.Selected = false;

    }

    }

    }));

    BeginInvoke() in Wisej is executed within the same request and on the same thread but after the entire request has been completed. It's basically a post-process callback. It allows an application to execute code asynchronously. Which is different from Application.StartTask().

    Hope that helps.

    Best regards
    Frank

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugSomething is broken or behaving unexpectedly.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions