0

I am trying to get the selected rows from a grid, when the user selects an option from a popup menu. I have the following code

    private void gridView1_PopupMenuShowing(object sender, 
    DevExpress.XtraGrid.Views.Grid.PopupMenuShowingEventArgs e)
    {
        if (e.MenuType != DevExpress.XtraGrid.Views.Grid.GridMenuType.Row) return;
        var item = new DXMenuItem("Delete");
        item.Click += (o, args) =>
        {
            var rowHandles = gridView1.GetSelectedRows();
            foreach (var rowHandle in rowHandles)
            {
                System.Data.DataRow row = gridView1.GetDataRow(rowHandle); 
                // debugger shows that rowHandle = 1 
                if (row == null)
                {
                    Console.WriteLine("how so?");  // breaks here
                }
            }
        };
        e.Menu.Items.Add(item);
    }

When I run in the debugger I would expect the row to be valid, however it is null.

Kirsten
  • 15,730
  • 41
  • 179
  • 318
  • https://documentation.devexpress.com/WindowsForms/DevExpress.XtraGrid.Views.Base.ColumnView.GetDataRow.method – Kirsten Oct 12 '19 at 03:11

1 Answers1

0

It turns out that since I have the grid getting data from a bindingsource and I am setting the bindingsource

the docs explain that GetDataRows will return null

If the View's data source is a custom collection of objects, the GetDataRow method returns null

Kirsten
  • 15,730
  • 41
  • 179
  • 318