Insert a new row in databound DGV...

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Saravanan Krishnan
    New Member
    • Mar 2008
    • 11

    Insert a new row in databound DGV...

    Hi, I've set the
    "AllowUserToAdd Rows = true;"
    and i want a new row to be added in the datagridview in the specific location.I am trying to add them programatically .
    I see an error that you cannot do that when the datagridview is bound to a bindingsource.
    If i edit a row, then a new row appears automatically at the last row. But what I need is to "insert" a row before or after a selected row and then add data to it.

    Thanks in advance...

    Saravanan Krishnan
  • Wagz
    New Member
    • Feb 2008
    • 11

    #2
    You can use

    Code:
    DataGridView1.Rows.Insert(index, paramArray)
    I don't think that works for bound DataGridViews though.

    Wagz

    Comment

    • Saravanan Krishnan
      New Member
      • Mar 2008
      • 11

      #3
      Actually i've binded the List<T> data to BindingSource then i've added the bindingsource to my DGV, what i needed was to insert a new row in the selected location of my DGV. By writting the below line of code (using the INSERT method of BindingSource) i achieved my required insertion of a new row in the selected location of the DGV.

      BindingSource1. Insert(e.RowInd ex, itemobj);

      Must write the above line of code in the ROWHEADERMOUSEC LICK EVENT of DGV to obtain the selected ROW's INDEX(ie., e.RowIndex).

      itemobj is the object of type Item Class which has various properties in it.

      What Wagz said throws an exception because DGV when DataBound doesnt allow Insert Method to insert a new row anywhere.

      So i thought why not to try using BindingSource, Then finally i got a new row inserted in the selected location of the DGV.

      Anyway, thanks for the try Wagz.

      Regards,
      Saravanan Krishnan
      Last edited by Saravanan Krishnan; Mar 20 '08, 10:35 AM. Reason: Not well formatted...

      Comment

      Working...