Solved

datagridview

Posted on 2006-07-11
2
616 Views
Last Modified: 2010-04-16
I am using datagridview in .net 2.0

I have a datagridview which I initially do not allow the users to AddNew.  However, the user can add a new record by pressing the button.  This works fine.  In the case the user would like to cancel their action, how do I remove the new record from the datagridview?

thanks.

Heidi.
0
Comment
Question by:yanci1179
2 Comments
 
LVL 44

Accepted Solution

by:
bruintje earned 300 total points
ID: 17085268
Hi yanci1179,
----------

this walkthrough discusses adding and deleting new rows to a datagridview
http://msdn2.microsoft.com/en-us/library/5s3ce6k8.aspx

the part most related to your question is this which deletes the selected row(s)

Private Sub deleteRowButton_Click(ByVal sender As Object, _
    ByVal e As EventArgs) Handles deleteRowButton.Click

    If Me.songsDataGridView.SelectedRows.Count > 0 AndAlso _
        Not Me.songsDataGridView.SelectedRows(0).Index = _
        Me.songsDataGridView.Rows.Count - 1 Then

        Me.songsDataGridView.Rows.RemoveAt( _
            Me.songsDataGridView.SelectedRows(0).Index)

    End If

End Sub

if your user undo's the addition of a new row you can use the currentrow property
http://msdn2.microsoft.com/en-us/library/system.windows.forms.datagridview.currentrow.aspx

----------
bruintje
share what you know, learn what you don't
0
 
LVL 1

Assisted Solution

by:flashaoy
flashaoy earned 200 total points
ID: 17092151
datagridview.Rows.Remove(datagridview.Rows[index])
0

Featured Post

ScreenConnect 6.0 Free Trial

Discover new time-saving features in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI, app configurations and chat acknowledgement to improve customer engagement!

Question has a verified solution.

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

Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

773 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