Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

How do I delete a row in a DataGridView?

Posted on 2007-11-28
5
Medium Priority
?
665 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 1500 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

RHCE - Red Hat OpenStack Prep Course

This course will provide in-depth training so that students who currently hold the EX200 & EX210 certifications can sit for the EX310 exam. Students will learn how to deploy & manage a full Red Hat environment with Ceph block storage, & integrate Ceph into other OpenStack service

Question has a verified solution.

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

This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…

715 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