Click here to Skip to main content
15,908,634 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,
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

1 solution

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.
 
Share this answer
 
Comments
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
DataGridView1.Refresh()
DataGridView1.Parent.Refresh()
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)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900