473,385 Members | 1,342 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,385 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
3 2265
In version 2005 this is organized direct in the datagridview

In version 2003 you have to do this using the dataview
http://msdn2.microsoft.com/en-us/lib...lowdelete.aspx

If you want to do this conditional, than you can try this one on our
website.

http://www.vb-tips.com/default.aspx?...9-57ec163eaa17

I hope this helps,

Cor
"Ryan Liu" <ad********@online.sh.cn> schreef in bericht
news:%2****************@TK2MSFTNGP09.phx.gbl...

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 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

"Cor Ligthert [MVP]" <no************@planet.nl> дÈëÓʼþ
news:eu**************@TK2MSFTNGP09.phx.gbl...
In version 2005 this is organized direct in the datagridview

In version 2003 you have to do this using the dataview
http://msdn2.microsoft.com/en-us/lib...lowdelete.aspx
If you want to do this conditional, than you can try this one on our
website.

http://www.vb-tips.com/default.aspx?...9-57ec163eaa17
I hope this helps,

Cor
"Ryan Liu" <ad********@online.sh.cn> schreef in bericht
news:%2****************@TK2MSFTNGP09.phx.gbl...

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 6 '06 #3
Ryan,

Is there any reason that you added that Original version tests.

I assume that the Original row will never been deleted. How the update can
than check if there are changes in the database and therefore concurrency
errors. There will be copies made, if you make an XML file you can write
those with the option for that.

I hope this helps,

Cor
Mar 6 '06 #4

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: Ryan McLean | last post by:
Hi everyone! What is happening is the method: sub_btnSubmitClicked is being executed every time any other object with a Handler is executed. I am trying not to use the withevents and handles...
1
by: Andrew | last post by:
Hey all, I am very new to ASP.Net (and .Net in general), but that isn't stopping the boss from wanting to begin new projects in it. This latest project has me kinda stumped and after a couple...
4
by: tshad | last post by:
I am having trouble with links in my DataGrid. I have Links all over my page set to smaller and they are consistant all over the page in both Mozilla and IE, except for the DataGrid. Here is a...
0
by: Mohammad Ali via DotNetMonster.com | last post by:
hi guys, I have a problem with my datagrid. My form is set up so I have two textboxes an add button and an editable datagrid. The datagrid is bound to a datatable which is in my cache.When 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...
5
by: Maria Anthonsen | last post by:
I have filled a datagrid with data from a dataset. The dataset was filled with a dataadapter - and I used the wizard to create insert, update, delete commands. I would like to prevent the user...
2
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...
4
by: =?Utf-8?B?cmFuZHkxMjAw?= | last post by:
I'm working in Visual Studio 2005 and C#. I have a DataTable with many rows. The user can delete a row. After the row is deleted, I'd like to column values for the deleted row, but any attempt to...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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...

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.