Question How to duplicate an selected row in a bound DataGridView

itms

Active member
Joined
Feb 21, 2018
Messages
31
Programming Experience
10+
Hi,

I am trying to, through a context menu, give the user the ability to select a record in a dtaview grid and paste it in the grid as a new record.
I have found very little on the web and the one thing that I tired errored stating that it can't copy a row into a bound grid.
So if anyone has any ideas I would appreciate it.

Thank you
 

jmcilhinney

VB.NET Forum Moderator
Staff member
Joined
Aug 17, 2004
Messages
14,203
Location
Sydney, Australia
Programming Experience
10+
You have posted in the wrong forum. The VS.NET General Discussion forum is for discussion of Visual Studio itself, not about code written in VS. We need more accurate information to determine where this question belongs. What type of application are you creating? Is it Windows Forms, WPF, ASP.NET Web Forms or something else? Also, what is the actual control? My guess would be a WinForms DataGridView. It is important that you ALWAYS provide a FULL and CLEAR explanation of the problem, which includes using the actual name of each type you use, rather than a vague approximation. In this case, there are various DataGrid, GridView and DataGridView controls available for various UI technologies and the answer to your question would be different for each one. You also indicate that your grid is bound so we would need to know to what. As the error message (which you also should have provided verbatim rather than a vague approximation) indicates, you can add rows directly to a DataGridView that is bound; you have to add an item to the data source instead. To that end, knowing what the data source is is a requirement, because copying an item will be different for different types of lists. Again, my guess is that you've bound a DataTable but we shouldn't have to guess.
 

itms

Active member
Joined
Feb 21, 2018
Messages
31
Programming Experience
10+
Hi,
Sorry if I dod not give enough detail here, as this concept is new to me too; but you are totally right in that the more info you have the better you can answer the question.
it is a WinForms DataGridView.
I am not sure if I am answering you right but I know it connects to a SQL Server 2012 database. I can also tell you that the grid is populated through a dataset.
This the exact message:
System.InvalidOperationException: 'Rows cannot be programmatically added to the DataGridView's rows collection when the control is data-bound.'
You said that I posted it to the wrong forum.
Should I move this to another forum, and if so, can you suggest which one?
Thank you
 
Top Bottom