473,848 Members | 1,590 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

datagrid validation

I have seen articles saying that validating the data a
user enters into a datagrid is difficult, because it is
not the datagrid itself that does the validation, but
rather textboxes that are in the cells. The article then
says that it is best to validate the datatable behind the
grid using row or column changing events.

I have a few questions about this.

If I am to use row or column data changing events on the
underlying table, is there a way I can keep those event
routines from being called when my program changes the
data in the table while they are still called when the
user modifies the data via the datagrid?

I find that if I bind to the datagrid a table that is in a
dataset that was loaded from a database via a data adapter
and one of the fields is numeric, that the datagrid
magically won't allow non-numeric entries in that column.
This is exactly what I want. How can I get this
functionality for a datatable I have not loaded from a

Is there someway I can have the datagrid use my own
validatedTextBo x (which inherits from textBox) for the
data entry in the cells that would then allow me to do the
validation I want.

By-the-way, all I need to do is make sure that valid
numbers have been entered in a cell. Any other way to do
this in a simple fashion would be welcome.


Nov 21 '05 #1
1 1258

The validating event is fired before a control loses his focus.

In the datagrid you have for that the rowchange and the column change event,
with the exception that that does not fire when there is a button event or
something like that.

However maybe this sample I made gives you some other ideas, it is not
completly your question, however should have the same results when other
events are used in my opinion.
(not tested)


Private WithEvents dtbCol1 As DataGridTextBox
Private ToolTip1 As New ToolTip
Private Sub Form1_Load(ByVa l sender As Object, _
ByVal e As System.EventArg s) Handles MyBase.Load
Datagrid1.ReadO nly = True
Dim ts As New DataGridTableSt yle
ts.MappingName = ds.Tables(0).Ta bleName
Dim column As New DataGridTextBox Column
ts.GridColumnSt yles.Add(column )
DataGrid1.Table Styles.Add(ts)
column = DirectCast(ts.G ridColumnStyles (0), DataGridTextBox Column)
dtbCol1 = DirectCast(colu mn.TextBox, DataGridTextBox )
column.MappingN ame = ds.Tables(0).Co lumns(0).Column Name
column.HeaderTe xt = "Cor"
column.Width = 30
dv = New DataView(ds.Tab les(0))
dv.AllowNew = False
DataGrid1.DataS ource = dv
End Sub
Private Sub dtbCol1_ToolTip (ByVal sender As Object, _
ByVal e As System.EventArg s) Handles dtbCol1.MouseEn ter
ToolTip1.SetToo lTip(DirectCast (sender, DataGridTextBox ), _
"Row: " & DataGrid1.Curre ntRowIndex + 1)
End Sub
Nov 21 '05 #2

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

Similar topics

by: ED M. | last post by:
Hello all...I'm new to the board. I have a problem that I hope someone here might be able to solve for me. I am doing some clientside validation using Javascript. The text I am testing is within a textbox that is part of a datagrid. To complicate things, the datagrid is part of a user control. The following code is all part of the user control. The validation part of the script works fine. However, when I try to set the focus...
by: GregM | last post by:
I have a read only datagrid that is designed to coordinate itself with textboxes. When the user clicks on a row in the datagrid, detailed data for that row is displayed for editing in the textboxes. The datagrid and textboxes are populated from the same underlying SQL Server table but using different strongly typed data adapters and datasets for display and editing. So I coordinate syncronization of the two sets of data using code. I use...
by: Stephan Bour | last post by:
Hi, I need to validate a text box in a datagrid nested inside a datalist. All I need is to validate that any text is entered in the textbox. However, a requiredfieldvalidator would not do because I want to perform the validation only on the datagrid rows where a check box is checked. Part of the datagrid: <asp:TemplateColumn HeaderText="C #"> <ItemTemplate>
by: Ben | last post by:
Hi, I have a page with a datagrid that you have to scroll to see. I'm using the StrengthControls SmartScroller as recommended to maintain my scroll position. Anyway, inside the datagrid I have fields that require validation. No problem, I put the validators on them and they work just fine... Except for the fact that when a user has an invalid entry and fires a validation event client side the scroll position is reset to the top of the...
by: rodchar | last post by:
Hey all, I've got an asp.net page that has a textbox on it. The textbox has a requiredfieldvalidation associated with it. I've also got a datagrid with the edit,update,cancel links on it. When I run my app, and select the update link on the datagrid my textbox validation fires. Not sure why? Note: if i close the application and restart it it works fine. no error.
by: Chris | last post by:
Based upon some prevoius postings on what to do for adding a 'add' row to a datagrid I utilize the footer to create the 'add' row. The only issue is that I have it sharing the 'UpDate_Command' and I use an argument to difference between an 'edit' vs. and 'add. But since I have field validation on both 'footer' and 'edit' columns I can't submit my edits since the footer validation kicks in.If I take the validation off then the both work fine...
by: siaj | last post by:
Hello All, If some one has faced a similar issue.. My datagrid Update command is not getting fired in fact it seems that the no event fires on clicking the update link. Although the cancel and the Edit Commmand are getting fired properly. The One difference I have seen is that in the task bar ..on hovering on the link the javascript for the update link seems different. I dont know if it makes sense..
by: David Colliver | last post by:
Hi all, I am having a slight problem that hopefully, someone can help me fix. I have a form on a page. Many items on the form have validation controls attached. Also on this form are linkbuttons which must not cause validation. I have found a setting "causeValidation" to disable the validation. Also on the page, I have a datagrid that I will edit lines on. I can click
by: Kris | last post by:
Hi, I have a DataGrid where in each row has couple of text boxes and an update button. Each row is dynamically generated as the number of rows are not known ahead of time. When the user clicks the update button, I do a postback to capture the data entered. However I dont want to do a postback when the textboxes are empty. How do I prevent this using Clientside validation? This is a common problem and if it has been beaten to death, please...
by: Tina | last post by:
the Edit, Update, Cancel, and Delete buttons in my datagrid are causing validation elsewhere on the page. I want to specify that these buttons should not cause validation but they have no design time property of causevalidation. How can I keep them from causing validation? Thanks, T
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.