且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Windows应用程序中动态生成的datagridview控件

更新时间:2023-12-06 10:50:04

有两种方法可以做到这一点:
首先,使用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 :)