grouchyfd
asked on
How do I delete a row in a DataGridView?
I have an ADO.Net app. In the app is an order form that is a master-detail form, for each order number, there is a datgridview where the user can select an item and qty then select the next row and add another item and qty. The datagrid can have multiple rows. How do I allow the user to delete a row if he/she determines they do not want that item any more, before the order is saved (and the table updated)? I have a button but I just can't seem to get the code to make it remove a highlighted row.
Thanks
Thanks
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
If the datagrid view is binded with a data source, all you have to do is to set the DataRowState to deleted. the item will be deleted once its posted to the
database.
database.
ASKER
Solar Flare
Thanks. I found that if I update the table and then delete the row with a DELETE command in the same sub, this works. I was hoping for a way to delete the row strait from the dataset before it was committed to the database but this still works fine.
Thanks. I found that if I update the table and then delete the row with a DELETE command in the same sub, this works. I was hoping for a way to delete the row strait from the dataset before it was committed to the database but this still works fine.
you can remove the row from the dataset entirely
this is the idea, you can use the table's row collection's .Remove method
dim row as datarow = datagridview.selectedrows( 0).Databou nditem.row
dataset1.tables(0).rows.Re move(row)
this is the idea, you can use the table's row collection's .Remove method
dim row as datarow = datagridview.selectedrows(
dataset1.tables(0).rows.Re
ASKER