473,326 Members | 2,133 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,326 software developers and data experts.

deleting a row in bound datagrid

I am using datagrid bound to a datatable:

DataTable dt = ...;
MyGrid.DataSource = new DataView(dt);

Now I am trying to intercept delete operation, when user highlights a row
and presses delete key. For this, I am using dt.RowDeleting event:

private void dt_RowDeleting(object sender, DataRowChangeEventArgs e)
{
DialogResult ret = MessageBox.Show("Are you sure?", "Data Grid",
MessageBoxButtons.YesNo, MessageBoxIcon.Hand);
if (ret != DialogResult.Yes)
{
if (e.Action == DataRowAction.Delete)
{
((DataTable)sender).RejectChanges();
//??? }
}
}

It shows the warning message, executes RejectChanges when I click NO, but it
does not seem to work: a row is deleted anyway. Probably, I need to use some
other method to cancel deleting, but I have no idea which one.

Does anybody know how to fix that?
Thank you.

Nov 16 '05 #1
2 8210
See my reply in the thread "Datagrid delete without a button"

--
Sincerely,
Dmitriy Lapshin [C# / .NET MVP]
Bring the power of unit testing to the VS .NET IDE today!
http://www.x-unity.net/teststudio.aspx

"Alex K." <Al***@discussions.microsoft.com> wrote in message
news:A6**********************************@microsof t.com...
I am using datagrid bound to a datatable:

DataTable dt = ...;
MyGrid.DataSource = new DataView(dt);

Now I am trying to intercept delete operation, when user highlights a row
and presses delete key. For this, I am using dt.RowDeleting event:

private void dt_RowDeleting(object sender, DataRowChangeEventArgs e)
{
DialogResult ret = MessageBox.Show("Are you sure?", "Data Grid",
MessageBoxButtons.YesNo, MessageBoxIcon.Hand);
if (ret != DialogResult.Yes)
{
if (e.Action == DataRowAction.Delete)
{
((DataTable)sender).RejectChanges();
//??? }
}
}

It shows the warning message, executes RejectChanges when I click NO, but
it
does not seem to work: a row is deleted anyway. Probably, I need to use
some
other method to cancel deleting, but I have no idea which one.

Does anybody know how to fix that?
Thank you.


Nov 16 '05 #2
Thank you Dmitriy for your advice. I am going to use that solution, although
it looks very strange that
1) DataGrid does not have cancellable event "delete row"
2) both DataTable events RowDeleted and RowDeleting cannot be cancelled. Then,
what's the point of having those events?

It is just bizarre that once DataGrid receives Delete keystroke from
Windows, nothing can be done from the code to prevent a row from being
deleted.

Hey, guys from Microsoft, are you listening?

Thank you

"Dmitriy Lapshin [C# / .NET MVP]" wrote:
See my reply in the thread "Datagrid delete without a button"

--
Sincerely,
Dmitriy Lapshin [C# / .NET MVP]
Bring the power of unit testing to the VS .NET IDE today!
http://www.x-unity.net/teststudio.aspx

"Alex K." <Al***@discussions.microsoft.com> wrote in message
news:A6**********************************@microsof t.com...
I am using datagrid bound to a datatable:

DataTable dt = ...;
MyGrid.DataSource = new DataView(dt);

Now I am trying to intercept delete operation, when user highlights a row
and presses delete key. For this, I am using dt.RowDeleting event:

private void dt_RowDeleting(object sender, DataRowChangeEventArgs e)
{
DialogResult ret = MessageBox.Show("Are you sure?", "Data Grid",
MessageBoxButtons.YesNo, MessageBoxIcon.Hand);
if (ret != DialogResult.Yes)
{
if (e.Action == DataRowAction.Delete)
{
((DataTable)sender).RejectChanges();
//??? }
}
}

It shows the warning message, executes RejectChanges when I click NO, but
it
does not seem to work: a row is deleted anyway. Probably, I need to use
some
other method to cancel deleting, but I have no idea which one.

Does anybody know how to fix that?
Thank you.


Nov 16 '05 #3

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

Similar topics

4
by: Aaron Ackerman | last post by:
I am using typed datasets in an N-Tier Windows app using VB.NET. I know this posting cannot be fully explained in a single post that is why I am asking for someone to point me to a real world...
2
by: Job Lot | last post by:
My DataGrid is bound to DataView as follow DataGrid1.DataSource = myDS.Tables("Client_Consultant").DefaultView User can either delete all the rows in the DataGrid on by pressing "Delete All"...
5
by: Mojtaba Faridzad | last post by:
Hi, with SetDataBinding( ) a DataGrid shows a DataView. user can select some rows in the grid by holding cotrol key. when user clicks on Delete button, I should delete all selected rows. I am...
2
by: NDady via DotNetMonster.com | last post by:
Hi, I have a datagrid populated from a dataset. On every row in the grid I have a delete button. When the user presses on the delete button I remove the row from the dataset and rebind the...
0
by: Robert Batt | last post by:
Hello I have a problem deleting rows from a datagrid that is bound to a dataset. The datagrid updates and inserts just fin so the binding to the dataset must be ok. However when I try to delete a...
1
by: Robert Batt | last post by:
Hello, I have a problem deleting from a datagrid bound to a dataset. then datagrid is bound as follows MyDatagrid.DataSource = Mydataset.Tables(strtable this works fine for adding and...
2
by: ksedran | last post by:
I am having a "not all variables bound" issue when trying to delete a row from a datagrid. I have a datagrid populated with data from a oracle table as follows: da = New...
9
by: Hamed | last post by:
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...
0
by: TonyJ | last post by:
Hello! I'm unsure when I can use a bound datagrid and when I can't. What limitations has a bound datagrid? 1. For example if I want to manipulate the data in the datasource before displaying...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
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...

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.