views:

295

answers:

2

Hi,

I have a windows form which has a DataGrid control (Not DataGridView) on it.

The DataGrid control is bound ot to a DataTable. Everytime the user presses delete button on one of the rows on the grid, I want to check a condition and stop the row from being deleted if the condition is false.

I have subscribed to the RowDeleting event of the DataTable, but i cant find a way to cancel to the delete operation performed by the user.

Has anyone come across this ?

Thanks in anticipation.

Raghu.

A: 

My first thought was to suggest "e.Cancel = true;" but that property isn't available.

Googling a bit I came across How do I cancel a row delete in a DataSet; please, take a look.

HTH

Rubens Farias
A: 

Rubens

Thanks for you response. I had already looked up that thread, but couldnt find a useful solution.

I just slightly modified my project, I now have a delete button instead of deleting directly from the datagrid itself.

I changed my DataTable to disallow any deletes

dataTable.DefualtView.AllowDelete = false

and in the delete button click handler, i wrote the following code:

(datagridStandardRates.DataSource as DataTable).Rows[datagridStandardRates.CurrentRowIndex].Delete();

This gives me complete control over when I want to delete a row.

Thanks once again for your help.

Raghu

Raghu