Link to home
Start Free TrialLog in
Avatar of Murray Brown
Murray BrownFlag for United Kingdom of Great Britain and Northern Ireland

asked on

Visual Studio 2005 DataGridView - Delete row of cells programatically

Hi

I am able to add rows programatically in my DataGridView, but cannot
find out how to delete them.

Thanks

Avatar of vb_jonas
vb_jonas
Flag of Sweden image

You have to work with the DataTable behind the grid, and from there delete the row.

MyDataTable.Select("ID=" & DeleteFirstRowWithThisID)(0).Delete



Avatar of Murray Brown

ASKER

Hi
Thanks
I am not quite sure what you mean by ID. Please would you give me an example.
My DataGridView is simply called DGV and I want to delete line 50
I missed - the datagridview has a rows.remove - method. So in your case, this works:

        dgv.Rows.Remove(dgv.Rows(50))


You should also update the adapter to remove the row from the database. Like you do in your add row - routine. Ok?

ASKER CERTIFIED SOLUTION
Avatar of vb_jonas
vb_jonas
Flag of Sweden image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Great thanks very much for that :-)