Windows应用程序中动态生成的datagridview控件 [英] Dynamically generated datagridview controls in windows Application
本文介绍了Windows应用程序中动态生成的datagridview控件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何从Windows应用程序中动态生成的datagridview控件中获取数据?
我在运行时生成了1个以上的datagridview.
请帮忙.
谢谢.
How to get data out from dynamically generated datagridview controls in a windows application?
I have more than 1 datagridview generated during run time.
Please help.
Thank you.
推荐答案
有两种方法可以做到这一点:
首先,使用datagridview自己的对象模型;
(我不确定确切的语法,但对于Visual Studio,这应该不是问题)
There are two ways to do this:
First, using the datagridview''s own object model;
(I''m not sure about the exact syntax but with Visual Studio, this shouldn''t be a problem)
foreach(DataGridViewRow row in dataGridView1.Rows)
{
// Do stuff with the row
foreach(DataGridViewCell cell in row.Cells)
{
// Do stuff with the cell
cell.Value;
}
}
其次,使用datagridview的数据源(如果它是来自数据库的DataTable)
Second, using the datasource of the datagridview if it is a DataTable from a database
DataTable dt = (DataTable) dataGridView1.DataSource;
foreach(DataRow row in dt.Rows)
{
// Do stuff with the row
}
希望对您有帮助
I hope this helps
您可以导出到Excel [ ^ ].
嗨AshokAmeela,
只需调用datagridview对象,即可从该datagridview获取数据.
例如:第一个datagridview对象-> dgv1
第二个datagridview对象-> dgv2
Hi AshokAmeela,
Just call datagridview object you get the data from that datagridview.
For Ex: First datagridview object --> dgv1
Second datagridview object --> dgv2
DataTable dtData1=(DataTable)dgv1.DataSource;
DataTable dtData2=(DataTable)dgv2.DataSource;
该代码对您有所帮助.
干杯:)
This code helpful to you.
Cheers :)
这篇关于Windows应用程序中动态生成的datagridview控件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文