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
Solved

datagridview

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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Introduction Although it is an old technology, serial ports are still being used by many hardware manufacturers. If you develop applications in C#, Microsoft .NET framework has SerialPort class to communicate with the serial ports.  I needed to…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

809 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