Search code examples
c#.netwinformsdatagrid

How do you delete a row from a DataGrid in C#?


I have an app for a Windows CE 6.5 mobile device. I am using Visual Studio 2008, coding in C# Windows Forms in a Smart Device Project. I have used a datagrid (not datagridview as these are not available). I am trying to delete the selected row but I cannot figure it out.

I have researched it but everything comes back with deleting from datagridview where you can use .selectedrow . Can anyone point me in the right driection as to how to do this?

Attached is a photo to show that selectedrow isnt an option

Options


Solution

  • You can use CurrencyManager class for this purpose like this:

    var manager = (CurrencyManager)this.BindingContext[dataGrid1.DataSource];
    var currentIndex = manager.Position;
    manager.RemoveAt(currentIndex);
    manager.Refresh();