473,386 Members | 1,715 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,386 software developers and data experts.

C# - Delete row being validated

I am catching the RowValidating event and would like to be able to delete the row if it fails my criteria. How is this done?
Oct 22 '07 #1
5 6971
Shashi Sadasivan
1,435 Expert 1GB
check if the row is valid according to you, and delte it from the dataset.
Then update your dataset !!!

Any problems with that?
Oct 22 '07 #2
check if the row is valid according to you, and delte it from the dataset.
Then update your dataset !!!

Any problems with that?

When I attempt to delete the row as follows:

database.Tables["Applications"].Rows[e.RowIndex].Delete();

in the rowvalidating event, an error message states that the rownumber does not exist. Is a new row actually in the dataset prior to it being validated?
Oct 23 '07 #3
Hi,

In the RowValidating event the row has not been added to the dataset yet.
You can access the values by casting the sender to the datagridview or whatever you are using, then accessing the rows there.
I'm not sure how you delete them from here though as again they still have not been added to the dataset and it threw an exception in the quick test I did.

A better alternative would be to use the RowValidated event if its available as the row at this point has been added to the dataset/datasource.
You should then be able to use the delete code you posted earlier.


Poitasal
Oct 24 '07 #4
Hi,

In the RowValidating event the row has not been added to the dataset yet.
You can access the values by casting the sender to the datagridview or whatever you are using, then accessing the rows there.
I'm not sure how you delete them from here though as again they still have not been added to the dataset and it threw an exception in the quick test I did.

A better alternative would be to use the RowValidated event if its available as the row at this point has been added to the dataset/datasource.
You should then be able to use the delete code you posted earlier.


Poitasal

As part of my validation process I need to catch DataRows that do not satisfy the constraints imposed upon the DataTable they are being stored in. If they do not satisfy the constraints they cannot be added to the DataSet and therefore I will not be able to delete them in the RowValidated event.

What I am looking for is some way to dismiss a row that fails my validation criteria (and possible the constraints) prior to the row being added to the DataSet, which could cause a run time error.
Oct 24 '07 #5
As part of my validation process I need to catch DataRows that do not satisfy the constraints imposed upon the DataTable they are being stored in. If they do not satisfy the constraints they cannot be added to the DataSet and therefore I will not be able to delete them in the RowValidated event.

What I am looking for is some way to dismiss a row that fails my validation criteria (and possible the constraints) prior to the row being added to the DataSet, which could cause a run time error.
Ok, the datagridview will already have thrown an error before the RowValidating event if the data doesn't match the column type in the datasource.
What you can do is subscribe to the DataError event (couldn't see it in the properties, so may need to be done in code.).
From here, you can check the exception etc and display a warning\do stuff before calling the DataGridView.Rows.RemoveAt to remove the row from the datagridview in this event. If you had more stringent requirements like this column needs to be below 10 etc, then you could check it in the RowValidated event and move it from the datasource.

Now there would be a problem with this method if the data was not allowed to be written to the datasource unless it met all your custom (value <10) conditions. In this case you can stop it by calling the cancel method (e.cancel = true) in the RowValidating event which stops the data from being added to the datasource.
This doesn't remove it from the gridview however. One way of removing this I suppose would be to rebind the datasource at this point.

There is one thing I noticed when I was doing this. The rowvalidating event is called when you close the form that the datagridview is on. If you have cancel=true here when this happens, it will not allow you to close the form. Something to be aware of. I didn't look any further into this.

Just to let you know, I'm assuming that your using a DataGridView in a winform cause the web gridview doesn't have these events.
Oct 25 '07 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: wooks | last post by:
I apologise if this has been asked before, it is a bit hard to search for. I have an xml schema which defines the elements in the namespace "urn:dummy". The schema does not contain any...
3
by: Teddybearsrcute8 | last post by:
Hello, This is my first time using the CSS validator.(http://jigsaw.w3.org) I created an external style sheet and validated the html document, but I'm not sure why I'm getting these errors....
5
by: Liam Caffrey | last post by:
Hi, It appears that binary_checksum can give the same checksum for different strings, which is a bit worrying. (I guess the algorithm is the problem in the context of a repeating pattern.) ...
3
by: mallik | last post by:
Seems like we have a strange problem. Development environment is win 2000 prof, IIS5.0, QA environment is Windows 2003 server, IIS 6.0. Everything works as expected on Dev. machine, but when...
2
by: Chris Kettenbach | last post by:
Does a control need to inherit an interface to be "validatable" :)? I have a custom control ascx file. I want to name it as the control to be validated by an asp:validator. When I do that, I get...
0
by: Agnes | last post by:
After the user delete the row, I need to re-calculate the whole datagrid's invoice amount, So I try the following code. but I am fail. Does anyone know how to do that ? I try the...
1
by: Simon Verona | last post by:
I'm confused! I have a usercontrol which is basically an extension of the textbox - it is hosted in the user control because there are other controls held on the usercontrol as well. I have...
5
by: =?Utf-8?B?QmVuIFIu?= | last post by:
Hi, In a .NET 2.0 winforms application, I've got a textbox that, when updated, uses the validated event to cascade the change to another textbox (along with another value). This works well if...
2
by: Tony | last post by:
Hello! There is an event Validating that can be used on TextBox that are very useful but there are also an event named Validated that I can't find much use of. Have you see any useful times...
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:
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
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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...
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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.