473,387 Members | 1,517 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

prevent a row from being deleted in datagrid/datatable


Can someone give a sample to prevent a row from being deleted in a
datatable?

I tried e.Row.RejectChanges(); in dt_RowDeleting() but seems does not work.

I need verify if there other data using data in this row before actually
remove it from datagrid.

I can certainly control with Delete button. But if I want to allow the user
to use Del key on the keyboard, I lost this kind control.

Thanks,
Ryan Liu
Mar 5 '06 #1
2 3466
I notice with some dismay that the RowDeleting event isn't cancelable,
as most other "...ing" events are.

Now, I've never tried this myself, but have you tried doing an
e.Row.RejectChanges() in the dt_RowDeleted() handler, rather than the
RowDeleting() handler? It seems logical that RejectChanges wouldn't do
anything in the RowDeleting event handler, because the row is "about to
be deleted," so there is as yet no change to reject. Perhaps in the
RowDeleted() handler the change will already have happened (thus the
"...ed" ending) and it will be possible to reject it.

Good luck.

Mar 6 '06 #2
I tried dt_RowDeleted() , but does not work really well.

The row still "disappear" from datagrid, even it is in datatable.

Even I try to set data grid's DataSource back again or call
dataGrid.Refresh(), or sort the grid,
neither way helps.

The row is still "seems" deleted from the datagrid, I mean, not visible.

But when I click the datagrid "existing data area", the missing row come
back!!

So now I need somehow make a fake mouse click to simulate this action. I
haven't finger out how yet.

By the way, I find I ofter need do this kind of fake action in code. I
thought EndEdit() could help, but does not.

For example, I want something to happen when the user click on a cell. But
Mouse event is not always fired if the current cell hasn't changed, I need
change current cell to someother cell in my code to make mouse down event
always triggered.

Another example is, when I try to move a row up and down in a datagrid, it
does not work well if there is a cell is seleted(even this column is read
only), I need use code to select whole line so no CurrentCell selected.

Oh, there is another thing, to get data in a deleted datarow, I forget to
use DataRowVersion, so there was an exception. But this exception is not
"throw" in the event dt_RowDeleted( ), it is an slient exception!! Take me a
while to find out the mysterious behavior.
private void dt_RowDeleted(object sender, DataRowChangeEventArgs e)
{
int id= (int)e.Row["id", DataRowVersion.Original];

if(id >5)
{
e.Row.RejectChanges();
MessageBox.Show(this, "Can not delete!"); //this worked,
message showed

//this.dataGrid.DataSource = this.dt.DefaultView; //set
DataSource again, but does not help
//this.dataGrid.Refresh();
//does not help
//this.dt.DefaultView.Sort = "id ASC"; //does
not help
}

}

Thanks,
Ryan Liu

"Bruce Wood" <br*******@canada.com> ????
news:11*********************@v46g2000cwv.googlegro ups.com...
I notice with some dismay that the RowDeleting event isn't cancelable,
as most other "...ing" events are.

Now, I've never tried this myself, but have you tried doing an
e.Row.RejectChanges() in the dt_RowDeleted() handler, rather than the
RowDeleting() handler? It seems logical that RejectChanges wouldn't do
anything in the RowDeleting event handler, because the row is "about to
be deleted," so there is as yet no change to reject. Perhaps in the
RowDeleted() handler the change will already have happened (thus the
"...ed" ending) and it will be possible to reject it.

Good luck.

Mar 6 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Chumley the Walrus | last post by:
IN my code behind .vb page for a delete records script (this also does a deletion confirmation with a javascript popup, this gets called on my front .aspx page with the datagrid), I'm not sure if...
1
by: Todd | last post by:
I just upgraded from the 2002.net to the 2003.net. I had been using a ..config file for database conection info. Now when I compile my application to debug the config file is being deleted out of...
4
by: simonmarkjones | last post by:
Hi i need to prevent a textfield on a form from being deleted from but allow updates/ append to any text already stored in the database. How can i do this?
0
by: GroZZleR | last post by:
Hey all, How can you expand the column sizes to ALWAYS take up atleast 100% of the DataGrid / DataTable? Right now my columns look like this: http://www.grozzler.com/dump/dt_mine.png I...
1
by: Daniel | last post by:
Hi all, I have problem in auto scroll to previous page when i try to delete the last row of the datagrid. The problem scenario is: 1.I click on next page of the datagrid. 2.I delete all the...
3
by: Ryan Liu | last post by:
Can someone give a sample to prevent a row from being deleted in a datatable? I tried e.Row.RejectChanges(); in dt_RowDeleting() but seems does not work. I need verify if there other data...
1
by: crka.crka | last post by:
Does anyone know a way to prevent a file being deleted so the only way to delete is via unistallation? Help would be very much appreciated.
2
by: Sean F. Aitken | last post by:
Good afternoon, We have an app that uses a CMap with CString types for values and accepts LPCSTR as the parameter. The object being created is on the heap (created dynamically). A leak detector...
1
by: Rob | last post by:
Is it possible to prevent a row from being deleted in a table. I want to arrange a new table with an autonumbered primary key that will form part of a set of sequential serial numbers. I want to...
3
by: tayalamit7 | last post by:
Hey guys plzz help me in this , i am trying to delete row in database using disconnected architecture . it shows item deleted in datatable but does not delete in database here is my code Dim...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.