Trying to understand the DataGridView

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Lloyd Sheen

    Trying to understand the DataGridView

    I am trying to find the event (if there is one) which occurs when a row
    is added to the DataGridView.

    The closest I can find is the RowsAdded event which says in documentation:

    Occurs after a new row is added to the System.Windows. Forms.DataGridV iew.

    OK then so I debug my code. I am adding 11 rows with a datasource and I
    get 4 occurences of the RowsAdded:

    ?e
    {System.Windows .Forms.DataGrid ViewRowsAddedEv entArgs}
    Empty: {System.EventAr gs}
    RowCount: 1
    RowIndex: 0

    {System.Windows .Forms.DataGrid ViewRowsAddedEv entArgs}
    Empty: {System.EventAr gs}
    RowCount: 11
    RowIndex: 1

    {System.Windows .Forms.DataGrid ViewRowsAddedEv entArgs}
    Empty: {System.EventAr gs}
    RowCount: 1
    RowIndex: 0

    {System.Windows .Forms.DataGrid ViewRowsAddedEv entArgs}
    Empty: {System.EventAr gs}
    RowCount: 11
    RowIndex: 1


    The call stack shows the same line:

    Me.SongInfoBind ingSource.DataS ource = newSource

    for each event occurrence and the above line is executed only once.
    This is somewhat confusing as it does not do as the documentation says
    and even so why is it doing the event four times and why oh why can the
    DataGridView not have events like in ASP.NET so that on each addition of
    a row it will give you an event so that you can do whatever is needed at
    that time?????

    Lloyd Sheen
  • Rich P

    #2
    Re: Trying to understand the DataGridView

    I would use a datasource table for the datagridview. The dataTable
    object is much easier to manage for adding/deleting/updating rows.
    Everything you do to the underlying dataTable gets displayed instantly
    on the datagridview

    Rich

    *** Sent via Developersdex http://www.developersdex.com ***

    Comment

    • Patrice

      #3
      Re: Trying to understand the DataGridView

      I repro the problem here. If you handle also RowsDeleted you'll better
      understand what's going on.

      Not familiar yet with this but this is where
      http://referencesource.microsoft.com/ could be usefull...

      For now it looks like rows are added then removed several times ??? I
      thought ti could be related to sortable columns but apparently not...



      --
      Patrice

      "Lloyd Sheen" <a@b.ca écrit dans le message de groupe de discussion :
      evHtmrvAJHA.376 8@TK2MSFTNGP04. phx.gbl...
      I am trying to find the event (if there is one) which occurs when a row is
      added to the DataGridView.
      >
      The closest I can find is the RowsAdded event which says in documentation:
      >
      Occurs after a new row is added to the System.Windows. Forms.DataGridV iew.
      >
      OK then so I debug my code. I am adding 11 rows with a datasource and I
      get 4 occurences of the RowsAdded:
      >
      ?e
      {System.Windows .Forms.DataGrid ViewRowsAddedEv entArgs}
      Empty: {System.EventAr gs}
      RowCount: 1
      RowIndex: 0
      >
      {System.Windows .Forms.DataGrid ViewRowsAddedEv entArgs}
      Empty: {System.EventAr gs}
      RowCount: 11
      RowIndex: 1
      >
      {System.Windows .Forms.DataGrid ViewRowsAddedEv entArgs}
      Empty: {System.EventAr gs}
      RowCount: 1
      RowIndex: 0
      >
      {System.Windows .Forms.DataGrid ViewRowsAddedEv entArgs}
      Empty: {System.EventAr gs}
      RowCount: 11
      RowIndex: 1
      >
      >
      The call stack shows the same line:
      >
      Me.SongInfoBind ingSource.DataS ource = newSource
      >
      for each event occurrence and the above line is executed only once. This
      is somewhat confusing as it does not do as the documentation says and even
      so why is it doing the event four times and why oh why can the
      DataGridView not have events like in ASP.NET so that on each addition of a
      row it will give you an event so that you can do whatever is needed at
      that time?????
      >
      Lloyd Sheen

      Comment

      Working...