Click here to Skip to main content
11,925,101 members (56,497 online)
Rate this:
Please Sign up or sign in to vote.
See more: VB VB.NET DataGridView
I'm using DatagridView in my VB.Net Project. Here the data can only be committed after users confirmation via a separate button. Though the user can delete the added rows till that time. I'm trying to make deleted rows invisible by following code:

DataGridView1.Rows(selectedIndex).Visible = False

However, getting following runtime error:
System.InvalidOperationException: "Uncommitted new row cannot be made invisible"

Please help in resolving the error or suggest an alternative to achieve the requirement.

Thanks in advance-*
Posted 15-Apr-13 6:42am

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

Don't commit the changes back to the database. Refresh the data set you've bound the grid to and whalla! No more uncommited records.
Vish0512 15-Apr-13 19:59pm
Hi Dave,
Thanks for your quick response... However, I've one more query here. How to refresh the dataset (I mean which method to use) as I didn't find any "refresh" method linked to dataset.
I tried with below code but it didn't work
Dave Kreskowiak 15-Apr-13 22:15pm
How did you fill the dataset to begin with? You do the exact same thing.
Vish0512 19-Apr-13 12:20pm
Hi Dave,
I was out of action for some days so delay in the response!!
See I'm totally new to VB.Net and as per my understanding when I fill my Dataset, the data is loaded from DB as per logic (our internal query for the fill method). However, in my case, I don't want to insert data in the DB and before committing, I want change in the set of data.

Let me give you complete picture. The requirement is for a project based on POS(Point of Sale) concept, where a user will select products and a record will be inserted in DGV. now if that user wants to remove any of the selected products, the system should allow him to do so before generating bill. So only one out of all uncommitted records will be removed and rest will remain visible

It is only when the user will click on Create Bill that the system should actually commit the record in DB.
Dave Kreskowiak 19-Apr-13 14:44pm
You don't store anything in the DGV. You should be storing the records in a DataSet/DataTable and manipulating that. The DGV is bound to this and is the control that displays the records on screen and allows editing them. You do NOT hide records in the DGV. If you don't want a record displayed, remove it from the datatable your bound the DGV to.

Vish0512 20-Apr-13 6:37am
Vow!! It was that simple. and I thought that making any change in datatable will directly run query on DB.. :-P
Thanks a lot Dave. That was really helpful.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.151125.3 | Last Updated 15 Apr 2013
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100