Click here to Skip to main content
15,891,981 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello ,


I have datagridview in which i am assigning datasource through query.
in that one column - Quantity is editable & its Format is set 0.00 from cellformating event.

Now if user delete any value & direct click on Cancel Button then it gives error as below.

"Operation did not succeed because the program cannot commit or quit a cell value change."

In Cancel Record we have to call FillGrid() in which first line code is as below ,

dgv.Datasource = null

In above line it throws error.

Also We have used _CellValidating Event in which we are checking whether user has entered proper value or not.

Thanks in Advance for help

Regards,
Developer
Posted
Comments
Richard MacCutchan 19-Feb-11 7:43am    
In above line it throws error.
Unless you show the exact text of the error message it is very difficult for anyone to guess what may be the problem.

Just a guess but calling dgv.CancelEdit() before setting the datasource to null might help.
 
Share this answer
 
Check your logic first in your code for every cell validation in grid and apply validation whenever it is required otherwise skip that validation and set default value to particular cell.

1)When we change any value in cell and it is not match with the datatype of cell that time grid throws an error.
2)When we write e.Cancel = True on cell validation event and then we try to change the data source of grid that time also same error throws.
 
Share this answer
 
I was getting this error in the following case:

1. Have a grid of say 20 rows.
2. My active cell was on say row 10.
3. I would filter the grid down to something less than 10 rows based on a simple find feature I have.
4. This caused the error because the current cell address no longer existed.

Now you'd think the grid would be smart enough to move the current cell to something that is available - but it seems that it doesn't do this.

My fix is to just set the current cell to the first column and first row before changing the number of rows:

C#
dgv.CurrentCell = dgv[0, 0];


That solved this problem for me.
 
Share this answer
 

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