How to supress deleting a Row

H

Hamed

Hello

I have a DataGrid that a is bound to a DataTable. Some of the rows in the
DataTable should not be deleted. How can I prohibit deleting of some
identified rows?

The problem could be specified in the following format too:

There is a DataView object that I want to prohibit deleting of some of its
DataRowView objects. that is: when drv.Delete() is called (drv is the
identified DataRowView) it doesn't delete the DataRowView object (suppress
that the Deleted tag is assigned to the RowState) . How can I do this job?


Regards
Hamed
 
A

AMDRIT

Datagridview
AllowUserToDeleteRows {true or false}

Datagrid
set the allow delete of the dataview that is bound to it to false

dim dt as datatable
dim dv as dataview
dim dbg as datagrid

'Get the default view from the table
dv = dt.defaultview

'Disallow deleted
dv.allowdelete = false

'Set the datasource
dbg.datasource = dv
 
H

Hamed

This technique disallows delete of whole grid. I want to prohibit delete of
some identified rows. for example I know that I should disallow deletion of
second row but others may be deleted.

Any help or comment is appreciated.

Hamed
 
G

Guest

Hamed,

I'm in now way an expert, but could you use the Hittest to find the row the
user is trying to delete, and check within that row for the occurance of the
piece of data that specifies when you don't want to allow deletion? You could
then simply disallow this deletion.

I suppose this solution is determined by how complicated your rules are for
allowing / not allowing rows to be deleted.

Perhaps a bit more information on what determines whether your rows can /
can't be deleted may help someone find you solution?

James.
 
H

Hamed

James

The case is not strange. It is simply a Grid of rows in a database
application. the rule is if any row is referred (or used) in another table,
it cannot be deleted using the Del key in the Grid. If I can somehow
prohibit delete of a specified row, I simply do the job for the rows in the
bound DataTable.

Regards
Hamed


P.S. As far as I know, Hittest checks physical position of a point in the
Grid rectangle, If I am wrong please correct me. If I am right, then this is
not my case. I want to disallow deletion of a certain row in a DataView or a
DataTable that is bound to a Grid and may have a lot of records so the Grid
scrolls. How does Hittest help in such a case?
 
G

Guest

Hamed,

Yes it checks a psyhical position, but at the same time that "could" have
been used. I assumed that you were indicating a user would have to select a
row to delete, therefore, if they had to select it, you would know which it
was! The Hittest would have then allowed you to indicate the row (and
therefore every cell referenced by that row) that was due to be deleted.

As I said, not knowing your rules, if it were (say for example) any row that
did not contain the number 3, in cell 4 (rough example!) you could have
checked in cell 4, for the value, and if were not 3, allow deletion,
otherwise, not allow it!

Maybe in the .NET days a complicated way of doing things, but i'm from the
days of VB6, and work arounds were part of the fun back then.

As I said in my original post, i'm not an expert, but just someone trying to
help.

James.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top