Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Visual Basic > VB.NET 1.0 > VB.NET 2002/2003 Basics
Password Reminder
Register
| FAQ | Members List | Search | Today's Posts | Mark Forums Read
VB.NET 2002/2003 Basics For coders who are new to Visual Basic, working in .NET versions 2002 or 2003 (1.0 and 1.1).
Welcome to the p2p.wrox.com Forums.

You are currently viewing the VB.NET 2002/2003 Basics section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old December 12th, 2003, 05:30 PM
Friend of Wrox
Points: 2,876, Level: 22
Points: 2,876, Level: 22 Points: 2,876, Level: 22 Points: 2,876, Level: 22
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Denver, CO, USA.
Posts: 428
Thanks: 57
Thanked 2 Times in 2 Posts
Default How do I get the CHANGED value in a datagrid cell?

I want to obtain the value entered into a datagrid cell in a VB.NET windows app (not ASP), so I can validate it before the change is applied to the dataset. The following code gets the ORIGINAL value in the cell, but I can't figure out how to obtain the NEW value:

grdServices.Item(grdServices.CurrentCell).ToString ()

What do I need to do to get the new value entered by the user? I've tried the _Validating function, which fires when the user leaves the cell (and, oddly, when the user enters another cell), but its arguments don't appear to contain any properties to obtain the NEW value, just the OLD one. Is there another method I should use or what?
Reply With Quote
  #2 (permalink)  
Old December 15th, 2003, 04:53 PM
Friend of Wrox
Points: 2,876, Level: 22
Points: 2,876, Level: 22 Points: 2,876, Level: 22 Points: 2,876, Level: 22
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Denver, CO, USA.
Posts: 428
Thanks: 57
Thanked 2 Times in 2 Posts
Default

Here's the answer I've finally found, if anybody cares:

Although it seems intuitive, you CANNOT check the new value by referencing the grid. It's necessary instead to reference the underlying table in the dataset (even though the table has NOT actually been updated - it makes no sense to me, but then very little MS has done with .NET makes sense to me) using the ColumnChanging event. Here's some genericized code that works:

Private Sub ColumnChangingValidation(ByVal sender As Object, _
  ByVal e As System.Data.DataColumnChangeEventArgs)

' first check the column name because this subroutine
' is not column specific (that would be too easy)
    If (e.Column.ColumnName.Equals("Server")) Then

            ' Validate e.ProposedValue, which is
            ' what the user entered
            If YourValidationRoutine(e.ProposedValue) = False Then

                ' set the row hover message on the table that
                ' makes it magically appear on the grid
                e.Row.RowError = "The Server column contains an error"

                ' set the column hover message on the table that
                ' makes it magically appear on the grid
                e.Row.SetColumnError(e.Column, "Value cannot be " & _ CType(e.ProposedValue, String) & " - Expected blah, blah, blah...")
            End If
        End If
    End Sub

Next, the ColumnChanging event has to be related to the table in the dataset:

AddHandler DataSetName.Tables("TableName").ColumnChanging, AddressOf ColumnChangingValidation

Then when the user enters a value into the indicated column and tabs out or clicks on another cell or another control, the event fires and the error indicator appears on the grid row and column. I haven't figured out hwo to cancel the update to the field in the table yet, but it should only take me another week or so to figure out that minor detail.

If you want to know how to do this in C#, you can find MicroSoft's ever-so-helpful example code at:

http://msdn.microsoft.com/library/de...ridcontrol.asp
Reply With Quote
  #3 (permalink)  
Old December 23rd, 2004, 10:51 AM
Registered User
 
Join Date: Dec 2004
Location: Utrecht, , Netherlands.
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Here's the answer for cancelling the update.

Example

Private Sub ColumnChangingValidation(ByVal sender As Object, _
            ByVal e As System.Data.DataColumnChangeEventArgs)
  'cancel the event
  'get the original value
    e.Row.Item(e.Column.Ordinal)
  'validate if this the right value
  'if not then set the proposed value back to original
    e.ProposedValue = e.Row.Item(e.Column.Ordinal)
End Sub

good luck
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Excel VBA Check When Cell Has Changed tonyrosen Excel VBA 13 March 24th, 2015 05:15 PM
How do I check if a cell content has changed SirAldemar Access VBA 2 August 13th, 2008 07:46 AM
Getting CHANGED value from Datagrid? Ron Howerton Pro VB.NET 2002/2003 5 January 5th, 2005 02:11 PM
DataGrid Cell mrideout BOOK: Beginning ASP.NET 1.0 0 August 17th, 2004 12:34 PM
selection index changed in datagrid lily611 General .NET 1 July 21st, 2004 07:56 AM



All times are GMT -4. The time now is 07:50 AM.


Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.