2 Replies - 954 Views - Last Post: 02 March 2012 - 07:37 PM Rate Topic: -----

#1 ebolisa  Icon User is offline

  • D.I.C Head

Reputation: 6
  • View blog
  • Posts: 141
  • Joined: 22-September 09

Inserting rows in datagridview

Posted 02 March 2012 - 03:31 PM

Hi,
I need to read data from a Excel sheet, manipulate it and send it back to another sheet. One of things I need to do is to duplicate each row in a dataviewgrig but when Iím inserting a row, I get an error in VB2010 stating that rows cannot be added when the datagridview is bonded.
Whatís the workaround, if any?
Thank you
Is This A Good Question/Topic? 0
  • +

Replies To: Inserting rows in datagridview

#2 DimitriV  Icon User is online

  • >not activating your almonds
  • member icon

Reputation: 560
  • View blog
  • Posts: 2,669
  • Joined: 24-July 11

Re: Inserting rows in datagridview

Posted 02 March 2012 - 03:48 PM

View Postebolisa, on 03 March 2012 - 08:31 AM, said:

Hi,
I need to read data from a Excel sheet, manipulate it and send it back to another sheet. One of things I need to do is to duplicate each row in a dataviewgrig but when Iím inserting a row, I get an error in VB2010 stating that rows cannot be added when the datagridview is bonded.
Whatís the workaround, if any?
Thank you

I did a search and a result that came up was:
"to add a row to a bound DataGridView you must add a row to the underlying data source" - ie the database your DataGridView is supposedly bound to.
Was This Post Helpful? 1
  • +
  • -

#3 CharlieMay  Icon User is offline

  • This space intentionally left blank
  • member icon

Reputation: 1533
  • View blog
  • Posts: 4,919
  • Joined: 25-September 09

Re: Inserting rows in datagridview

Posted 02 March 2012 - 07:37 PM

Exactly. If your datagridview has a datasource then you can no longer use DataGridView.Rows.Add, you will need to use the AddNew method of the datasource to add them. This will then refresh the datasource which should refresh the grid that is bound to it.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1