I have a datagrid which contains 3 columns. The user inputs data into the third column. I want to compare the contents of the last two columns to see if the user input the same data. When I attempt to access the data with dgMyGrid(Row,Column), I get the old value from the cell rather than the new value typed in by the user. How do I access the value the user typed in? Any help will be much appreciated.
Comments
:
:
VB6 or VB.net?
: :
: :
: VB6 or VB.net?
:
Sorry I forgot to specify that I am using VB.NET. I have now noticed that if I move to another row in the datagrid and them move back, then I can access the new value typed in by the user.
:
:
try this code
Private Sub dgrChecks_Validated(ByVal sender As Object, ByVal e As System.EventArgs) Handles dgrChecks.Validated
' Store the old value in a variable
mstrOldValue = dgrChecks(dgrChecks.CurrentCell.RowNumber, dgrChecks.CurrentCell.ColumnNumber).ToString
End Sub
Private Sub dgrChecks_CurrentCellChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles dgrChecks.CurrentCellChanged
'validate only if the value has changed
If mstrOldValue <> (dgrChecks(moldCellRow, moldCellColumn) & "") Then
'write your validate code
' if new value is invalid then use the following code to set focus back to the cell
dgrChecks.CurrentCell = New DataGridCell(moldCellRow, moldCellColumn)
dgrChecks(moldCellRow, moldCellColumn) = mstrOldValue
' will store the cell row/column of the current cell so that it can be used to read values when the focus shift to a different cell
moldCellRow = dgrChecks.CurrentCell.RowNumber
moldCellColumn = dgrChecks.CurrentCell.ColumnNumber
End If
End Sub
JP
: : I have a datagrid which contains 3 columns. The user inputs data into the third column. I want to compare the contents of the last two columns to see if the user input the same data. When I attempt to access the data with dgMyGrid(Row,Column), I get the old value from the cell rather than the new value typed in by the user. How do I access the value the user typed in? Any help will be much appreciated.
: :
: :
:
: try this code
:
:
: Private Sub dgrChecks_Validated(ByVal sender As Object, ByVal e As System.EventArgs) Handles dgrChecks.Validated
: ' Store the old value in a variable
: mstrOldValue = dgrChecks(dgrChecks.CurrentCell.RowNumber, dgrChecks.CurrentCell.ColumnNumber).ToString
: End Sub
:
: Private Sub dgrChecks_CurrentCellChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles dgrChecks.CurrentCellChanged
: 'validate only if the value has changed
: If mstrOldValue <> (dgrChecks(moldCellRow, moldCellColumn) & "") Then
: 'write your validate code
:
: ' if new value is invalid then use the following code to set focus back to the cell
: dgrChecks.CurrentCell = New DataGridCell(moldCellRow, moldCellColumn)
: dgrChecks(moldCellRow, moldCellColumn) = mstrOldValue
:
: ' will store the cell row/column of the current cell so that it can be used to read values when the focus shift to a different cell
: moldCellRow = dgrChecks.CurrentCell.RowNumber
: moldCellColumn = dgrChecks.CurrentCell.ColumnNumber
: End If
: End Sub
:
: