将数据从datatable移动到datagridview在C# [英] Moving data from datatable to datagridview in C#
问题描述
我的问题是:如何将datatable(dt)放入datagridview(dataGridView1)?我会做这样的事情吗?:
dataGridView1.column(MemberSep)= dt.column(MBRNUM);
我想我可以循环通过datatable,计算我的前两列的值datagridview,然后将它全部写到一行,直到我读完整个datatable之前,我从未使用过datagridview控件,任何帮助将不胜感激。
将DataGridView的 DataSource
设置为 DataTable
。
I have a C# program that selects data from two different database files and combines the data that I need into a datatable (dt). All the information I need is in that datatable, and I want to put it into a datagridview. Besides the information in the datatable, I also have two columns in the datagridview that I'll calculate as I add each row to the datagridview (dataGridView1).
My question is: How can I get my datatable (dt) into the datagridview (dataGridView1)? Would I do something like this?:
dataGridView1.column("MemberSep") = dt.column("MBRNUM);
I'm thinking that I could loop through the datatable, calculate the values for my first two columns of the datagridview, and then write it all to a row until I've read the whole datatable. I've never worked with a datagridview control before. Any help would be greatly appreciated.
Set the DataGridView's DataSource
to the DataTable
.
这篇关于将数据从datatable移动到datagridview在C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!