Solved

How do I delete a row in a DataGridView?

Posted on 2007-11-28
5
655 Views
Last Modified: 2013-11-26
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
0
Comment
Question by:grouchyfd
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 15

Accepted Solution

by:
Solar_Flare earned 500 total points
ID: 20369557
if the datagridview is databound then you will need to remove the row from the underlying data source rather than trying to remove the actual datagridviewrow from the control.
0
 

Author Comment

by:grouchyfd
ID: 20370313
The data is not committed to the database yet, it's just stored in a dataset. I would like the user to be able to remove the selected or highlighted row from the dataset.
0
 
LVL 5

Expert Comment

by:ursangel
ID: 20371701
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.
0
 

Author Comment

by:grouchyfd
ID: 20375621
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.
0
 
LVL 15

Expert Comment

by:Solar_Flare
ID: 20378259
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).Databounditem.row

dataset1.tables(0).rows.Remove(row)
0

Featured Post

SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

IP addresses can be stored in a database in any of several ways.  These ways may vary based on the volume of the data.  I was dealing with quite a large amount of data for user authentication purpose, and needed a way to minimize the storage.   …
This article describes relatively difficult and non-obvious issues that are likely to arise when creating COM class in Visual Studio and deploying it by professional MSI-authoring tools. It is assumed that the reader is already familiar with the cla…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question