How to detect datagrid row change

B

Brian Tkatch

How do i detect a datagrid row change?

Currently, i have a few datagrids that i keep in sync, refreshing from
the database whenver a row changes. I would like to avoid
CurrentCellChanged because changing a cell within the same row causes
an uneccesary DB call. Also, when the row changed to is the "new" row,
nothing should happen.

I wrote some code, which indeed works, but would like to know if i am
missing something more obvious.

When a grid is Fill()ed, it stores count in a variable like
Grid_Row_Count = Data_Set.Tables([table_name]).DefaultView.Count

Private Sub Grid_CurrentCellChanged(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles Grid.CurrentCellChanged

Static Current_Row As Integer

If Grid.CurrentRowIndex = Current_Row _
Or Grid.CurrentRowIndex = Grid_Row_Count Then Exit Sub

Current_Row = Grid.CurrentRowIndex

Fill_Child_Grid()

End Sub

B.
 
B

Brian Tkatch

Kerry said:
Brian,

This might work for you:

http://www.syncfusion.com/FAQ/WindowsForms/FAQ_c44c.aspx#q823q

Kerry Moorman


Brian Tkatch said:
How do i detect a datagrid row change?

Currently, i have a few datagrids that i keep in sync, refreshing from
the database whenver a row changes. I would like to avoid
CurrentCellChanged because changing a cell within the same row causes
an uneccesary DB call. Also, when the row changed to is the "new" row,
nothing should happen.

I wrote some code, which indeed works, but would like to know if i am
missing something more obvious.

When a grid is Fill()ed, it stores count in a variable like
Grid_Row_Count = Data_Set.Tables([table_name]).DefaultView.Count

Private Sub Grid_CurrentCellChanged(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles Grid.CurrentCellChanged

Static Current_Row As Integer

If Grid.CurrentRowIndex = Current_Row _
Or Grid.CurrentRowIndex = Grid_Row_Count Then Exit Sub

Current_Row = Grid.CurrentRowIndex

Fill_Child_Grid()

End Sub

B.

Thanx, i appreciate the reply. And that page looks pretty interesting.

Though, that looks a little more complex than what i am doing.

After adding the binding manager, how is it's event triggered?

For the new row, is using a binding manager better than just saving a
class-wide (form)variable holding the number?

The reason i used a variable, is that once the new row is hit, it
automatically increments the datasource's row count, giving me no way
of knowing if it was just added. The code he posted merely checks that
count "((DataTable)dataGrid1.DataSource).Rows.Count;", how does it know
that the record was not added just then?

B.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top