• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 603
  • Last Modified:

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
0
Midnight2005
Asked:
Midnight2005
1 Solution
 
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 CroweCommented:
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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
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

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now