Validation in DataGrid ?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Arsalan

    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?


  • Michael C#

    #2
    Re: Validation in DataGrid ?

    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" <arsalan_aslam@ hotmail.com> wrote in message
    news:%23dDE17ID FHA.624@TK2MSFT NGP15.phx.gbl.. .[color=blue]
    > 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?
    >[/color]


    Comment

    • Ken Tucker [MVP]

      #3
      Re: Validation in DataGrid ?

      Hi,

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

      Add Tablestyle




      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" <arsalan_aslam@ hotmail.com> wrote in message
      news:%23dDE17ID FHA.624@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?



      Comment

      • Michael C#

        #4
        Re: Validation in DataGrid ?

        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]" <vb2ae@bellsout h.net> wrote in message
        news:O2dGFwTDFH A.1524@TK2MSFTN GP09.phx.gbl...[color=blue]
        > 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" <arsalan_aslam@ hotmail.com> wrote in message
        > news:%23dDE17ID FHA.624@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?
        >
        >
        >[/color]


        Comment

        Working...