Datagrid Cell value

I am working on VS 2005.

I have a datagrid with bunch of rows.
        Dim objCommand As SqlCommand = New SqlCommand("sp_ReturnCrossTab", objConn)
        daSp = New SqlDataAdapter(objCommand)
        daSp.Fill(dsEmSP)

        DataGridView1.DataSource = dsEmSP.Tables(0)

---
At datagrid.cellvaluechange event , I am reading the new value, is there a way to read the value just being replaced?
I looked at that state, these came up, but I couldn't see the old value:
? DataGridView1.IsCurrentCellInEditMode
True
? DataGridView1.IsCurrentCellDirty
True
? DataGridView1.IsCurrentRowDirty
True


Is it possible to see what was in the cell?
Thanks
LVL 1
Midnight2005Asked:
Who is Participating?
 
Bob LearnedCommented:
I am not sure about the DataGridView, but the DataTable has the ColumnChanging event:

Dim dt As DataTable = dsEmSP.Tables(0)
AddHandler dt.ColumnChanging, AddressOf OnColumnChanged

Private Sub OnColumnChanged(ByVal sender As Object, ByVal e As DataColumnChangeEventArgs)

   Dim oldValue As String = e.Row(e.Column.ColumnName).ToString()
   Dim newValue As String = e.ProposedValue.ToString()

End Sub

Bob
0
 
Brian CroweDatabase AdministratorCommented:
You can get to the orignal value via a dataview using

dataview.rowstate = originalrows

However, I'm not sure how you tie that view reliably to the datasource of your datagridview especially if you allow the user to sort the datagridview.
0
 
iboutchkineCommented:
dgv.CurrentCell = dgv(iCol, iRow)
 s = dgv.CurrentCell.Value.ToString

msgbox(s)
0
Cloud Class® Course: Microsoft Office 2010

This course will introduce you to the interfaces and features of Microsoft Office 2010 Word, Excel, PowerPoint, Outlook, and Access. You will learn about the features that are shared between all products in the Office suite, as well as the new features that are product specific.

 
Midnight2005Author Commented:
TheLearnedOne,
I liked your datatable columnchange event, I am trying to use it, but it is also catching multiple times when the datagrid is loading the very first time. How can I prevent my code to run during these loadings?
0
 
Midnight2005Author Commented:
iboutchike,
Your code is giving the current value. Thank you though
0
 
Bob LearnedCommented:
One thought:

Add a flag like _isLoading at module level:

   Private _isLoading As Boolean = True

Once the form is loaded, set _isLoading = False.

In the event handler, check to see if the form loading flag is false

Private Sub OnColumnChanged(ByVal sender As Object, ByVal e As DataColumnChangeEventArgs)

   If Not _isLoading Then
     Dim oldValue As String = e.Row(e.Column.ColumnName).ToString()
     Dim newValue As String = e.ProposedValue.ToString()
   End If

End Sub

Bob
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.