473,385 Members | 1,453 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.

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 2141
I've done something similar with the DataGrid's .CurrentCellChanged event.
It might look something like this:

Private Sub dgPayroll_CurrentCellChanged(ByVal sender As Object, ByVal e As
System.EventArgs) Handles dgPayroll.CurrentCellChanged
' 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.CurrentCell.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.ToSingle(curGrid.Item(curRow, 1))
curGrid.Item(curRow, 2) = monthlyPay * 12.0
Catch
End Try
End Sub

"Arsalan" <ar***********@hotmail.com> wrote in message
news:%2***************@TK2MSFTNGP15.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 datagridtextboxcolumns 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 DatagridTextboxcolumn

With colDescription

..MappingName = "Notes"

..HeaderText = "Notes"

..Width = 350

End With

AddHandler colDescription.TextBox.Validating, AddressOf CellValidating

Private Sub CellValidating(ByVal sender As Object, ByVal e As
System.ComponentModel.CancelEventArgs)

Debug.WriteLine(DirectCast(sender, DataGridTextBox).Text)

End Sub
Ken

------------------------
"Arsalan" <ar***********@hotmail.com> wrote in message
news:%2***************@TK2MSFTNGP15.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***@bellsouth.net> wrote in message
news:O2**************@TK2MSFTNGP09.phx.gbl...
Hi,

First add a tablestyle to the datagrid then I would add a handler to
the datagridtextboxcolumns 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 DatagridTextboxcolumn

With colDescription

.MappingName = "Notes"

.HeaderText = "Notes"

.Width = 350

End With

AddHandler colDescription.TextBox.Validating, AddressOf CellValidating

Private Sub CellValidating(ByVal sender As Object, ByVal e As
System.ComponentModel.CancelEventArgs)

Debug.WriteLine(DirectCast(sender, DataGridTextBox).Text)

End Sub
Ken

------------------------
"Arsalan" <ar***********@hotmail.com> wrote in message
news:%2***************@TK2MSFTNGP15.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
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...
3
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...
1
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...
1
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...
3
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...
2
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...
5
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...
4
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...
1
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...
5
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...
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...
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: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: 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
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.