Solved

datagridview

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

[Webinar] Learn How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

Question has a verified solution.

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

We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
There's a multitude of different network monitoring solutions out there, and you're probably wondering what makes NetCrunch so special. It's completely agentless, but does let you create an agent, if you desire. It offers powerful scalability …
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

617 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