datagridview and datatable

K

kjqua

Hi every one.

I will like to know if is possible to copy data from a datagridview to a
datatable. If is possible how can i do it.
The datagrigview is not connect to a source, i add manually data to the
datagridview.

thanks
marco
 
B

Bob Powell [MVP]

Why not manually add the data to a datatable and then use the datadable as
the source?

Alternatively, create a class with properties that correspond to the columns
of your data and then use a BindingList of these objects bound to the
datagrid. The data will be updated for you.

--
--
Bob Powell [MVP]
Visual C#, System.Drawing

Ramuseco Limited .NET consulting
http://www.ramuseco.com

Find great Windows Forms articles in Windows Forms Tips and Tricks
http://www.bobpowell.net/tipstricks.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/faqmain.htm

All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.
 
K

kjqua

Bob, Thanks for your answer
Why not manually add the data to a datatable and then use the datadable
as the source?

I have 2 datagridView
the first one is connect to a database
the second DGV is connect to noting is populate from the first DGV by a
button. I select a row from the first DGV then true a button copy the
row of the first DGV to the second DGV.
Then i need to copy temporally all the data on the 2 DGV to the
DataTable, then do some work.
Alternatively, create a class with properties that correspond to the
columns of your data and then use a BindingList of these objects bound
to the datagrid. The data will be updated for you.

Please can you direct mi where can i get some example.

thanks
marco
 
G

Gopal

Bob, Thanks for your answer


I have 2 datagridView
the first one is connect to a database
the second DGV is connect to noting is populate from the first DGV by a
button. I select a row from the first DGV then true a button copy the
row of the first DGV to the second DGV.
Then i need to copy temporally all the data on the 2 DGV to the
DataTable, then do some work.




Please can you direct mi where can i get some example.

thanks
marco



- Hide quoted text -

- Show quoted text -

Marco,

Instead of adding data directly into DataGridView and then copy it to
a DataTable, you can try the following approach.
1) Create a new DataTable
2) Add each record from the first DataGridView's datatable to the
newly created datatable.
3) Bind the newly created datatable to the second DataGridView.

Hope this would solve your problem. Please let me know incase of any
issue/clarification.

Thanks,
Gopal
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top