Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

datagridview

Posted on 2006-07-11
2
Medium Priority
?
630 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 1200 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 800 total points
ID: 17092151
datagridview.Rows.Remove(datagridview.Rows[index])
0

Featured Post

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

Question has a verified solution.

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

In order to hide the "ugly" records selectors (triangles) in the rowheaders, here are some suggestions. Microsoft doesn't have a direct method/property to do it. You can only hide the rowheader column. First solution, the easy way The first sol…
This article introduced a TextBox that supports transparent background.   Introduction TextBox is the most widely used control component in GUI design. Most GUI controls do not support transparent background and more or less do not have the…
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …

876 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