473,698 Members | 2,171 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Validation in DataGrid ?

How do I validate inputs in DataGrid ? I want to check for constraint and
change columns value dynamically,

for e.g i've column named employee, annual salary and salary

I want the columns annual salary to be dynamically changed when user changes
salary in datagrid

How do I do it?
Nov 21 '05 #1
3 2155
I've done something similar with the DataGrid's .CurrentCellCha nged event.
It might look something like this:

Private Sub dgPayroll_Curre ntCellChanged(B yVal sender As Object, ByVal e As
System.EventArg s) Handles dgPayroll.Curre ntCellChanged
' This routine automatically calculates the Yearly Salary based on the
' Monthly Pay amounts entered

' First we locate our current edited cell and get the row
Dim curGrid As DataGrid = CType(sender, DataGrid)
Dim curRow As Integer = curGrid.Current Cell.RowNumber

' Then we get the gross pay and withholding from that row and
' calculate the net pay. We put it in a try..catch block to catch
' null values.

Try
' Assumes Monthly Pay is entered in column 1
' and Yearly Salary goes into column 2
Dim mothlyPay As Single = Convert.ToSingl e(curGrid.Item( curRow, 1))
curGrid.Item(cu rRow, 2) = monthlyPay * 12.0
Catch
End Try
End Sub

"Arsalan" <ar***********@ hotmail.com> wrote in message
news:%2******** *******@TK2MSFT NGP15.phx.gbl.. .
How do I validate inputs in DataGrid ? I want to check for constraint and
change columns value dynamically,

for e.g i've column named employee, annual salary and salary

I want the columns annual salary to be dynamically changed when user
changes salary in datagrid

How do I do it?

Nov 21 '05 #2
Hi,

First add a tablestyle to the datagrid then I would add a handler to
the datagridtextbox columns textbox validating event.

Add Tablestyle
http://msdn.microsoft.com/library/de...asicprimer.asp

http://msdn.microsoft.com/library/de...stdatagrid.asp

Add a handler to the textbox validating event
Dim colDescription As New DatagridTextbox column

With colDescription

..MappingName = "Notes"

..HeaderText = "Notes"

..Width = 350

End With

AddHandler colDescription. TextBox.Validat ing, AddressOf CellValidating

Private Sub CellValidating( ByVal sender As Object, ByVal e As
System.Componen tModel.CancelEv entArgs)

Debug.WriteLine (DirectCast(sen der, DataGridTextBox ).Text)

End Sub
Ken

------------------------
"Arsalan" <ar***********@ hotmail.com> wrote in message
news:%2******** *******@TK2MSFT NGP15.phx.gbl.. .
How do I validate inputs in DataGrid ? I want to check for constraint and
change columns value dynamically,

for e.g i've column named employee, annual salary and salary

I want the columns annual salary to be dynamically changed when user changes
salary in datagrid

How do I do it?

Nov 21 '05 #3
I tell you, I learn something new every time I visit this board! :) Just
one question - how can you update the yearly salary cell on the same row to
reflect the re-calculated salary?

Thanks!

"Ken Tucker [MVP]" <vb***@bellsout h.net> wrote in message
news:O2******** ******@TK2MSFTN GP09.phx.gbl...
Hi,

First add a tablestyle to the datagrid then I would add a handler to
the datagridtextbox columns textbox validating event.

Add Tablestyle
http://msdn.microsoft.com/library/de...asicprimer.asp

http://msdn.microsoft.com/library/de...stdatagrid.asp

Add a handler to the textbox validating event
Dim colDescription As New DatagridTextbox column

With colDescription

.MappingName = "Notes"

.HeaderText = "Notes"

.Width = 350

End With

AddHandler colDescription. TextBox.Validat ing, AddressOf CellValidating

Private Sub CellValidating( ByVal sender As Object, ByVal e As
System.Componen tModel.CancelEv entArgs)

Debug.WriteLine (DirectCast(sen der, DataGridTextBox ).Text)

End Sub
Ken

------------------------
"Arsalan" <ar***********@ hotmail.com> wrote in message
news:%2******** *******@TK2MSFT NGP15.phx.gbl.. .
How do I validate inputs in DataGrid ? I want to check for constraint and
change columns value dynamically,

for e.g i've column named employee, annual salary and salary

I want the columns annual salary to be dynamically changed when user
changes
salary in datagrid

How do I do it?

Nov 21 '05 #4

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

Similar topics

1
1364
by: Hi | last post by:
I have a ASP.Net page that has a few fields to submit to a database and a datagrid to edit the entries. I have validation controls to make sure the user enters the right info on the first few fields. In the datagrid, I have it set up dynamic so they can edit the dtabase records from the database. They click edit and they can edit a few fields and then press either update or cancel. The problem I have now is that when the user presses...
3
1277
by: Stephen | last post by:
I have two datagrids on a page and each of them allow the user to add rows. On each datagrid I have validation (required field, reg expressions etc) and my problem is that I only want the validation to work on the datagrid which I click add in. At the moment if I click add in one datagrid and haven;t filled out anything on the other datagrid then the validation comes up. Does any one know what I can do to combat this?
1
1356
by: claire | last post by:
Hi, I have a windows form with a datagrid. The datagrid is bound to a typed dataset. Is there a built in validation function for windows forms? To validate the text boxes i have extended the textbox. However i am not sure how to perform validation on a datagrid. should i just catch the sql exceptions? Thank you in advance for any help you can give me, as i havent been able to
1
1179
by: Stephen | last post by:
I have two datagrids on a page and each of them allow the user to add rows. On each datagrid I have validation (required field, reg expressions etc) and my problem is that I only want the validation to work on the datagrid which I click add in. At the moment if I click add in one datagrid and haven;t filled out anything on the other datagrid then the validation comes up. Does any one know what I can do to combat this?
3
2998
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...
2
1505
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.
5
3241
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...
4
2971
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
1
2380
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...
5
2052
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
0
8674
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8603
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,...
0
8861
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7721
agi2029
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...
1
6518
isladogs
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...
0
5860
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();...
0
4615
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3045
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
2
2327
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.