Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

DataGridView cancel cell changes

Status
Not open for further replies.

johnisotank

Technical User
Aug 8, 2008
258
0
0
GB
Hi all,

I have a datagridview with 5 columns.

Column 1 of the DGV should only be allowed to be edited if certain criteria has been met. If it hasn't, I would like to be able to change the value back to what it was.

At the moment the column is NOT read-only so the user can freely type but at the point of CellEndEdit I have some code which tells him he can't edit the cell because the criteria has not been met but it still accepts the changes he has made.

Is there anyway to call something like cell.cancelchanges or cell.revertchanges?

here is my code

Code:
 Private Sub MyDataGridView_CellEndEdit(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles MyDataGridView.CellEndEdit
'Check criteria is met
If string <> "ABC" Then
MsgBox("You cannot edit this cell")
End If
End Sub

 
Does the criteria apply to the entire grid, or is this on a row-by-row basis?

If it's row-by-row, the problem with this that I see would be that the user interface gets a bit complicated and unnatural.

However, rather than "undoing" the changes, I would rather them not be made in the first place. You can set an individual cell to read-only.

 
Hi Riverguy,

That link got me going in the right direction, working perfect now.

it is actually on a row by row basis but isn't complicated at all and behaves perfect so thanks for that.

cheers
John


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top