Solved

datagridview

Posted on 2006-07-11
2
614 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

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Introduction This article series is supposed to shed some light on the use of IDisposable and objects that inherit from it. In essence, a more apt title for this article would be: using (IDisposable) {}. I’m just not sure how many people would ge…
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…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

760 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now