Home All Groups Group Topic Archive Search About

How to detect datagrid row change

Author
26 Jun 2006 5:32 PM
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.

Author
26 Jun 2006 6:01 PM
Kerry Moorman
Brian,

This might work for you:

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

Kerry Moorman


Show quoteHide quote
"Brian Tkatch" wrote:

> 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.
>
>
Author
26 Jun 2006 7:43 PM
Brian Tkatch
Kerry Moorman wrote:
Show quoteHide quote
> Brian,
>
> This might work for you:
>
> http://www.syncfusion.com/FAQ/WindowsForms/FAQ_c44c.aspx#q823q
>
> Kerry Moorman
>
>
> "Brian Tkatch" wrote:
>
> > 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.