winform中dataGridView绑定DataTable中的详细信息

View Code
1 // 绑定详细信息
2 private void bindfinance(DataTable dt)
3 {
4 dgvfinance.Columns.Clear();
5 dgvfinance.Rows.Clear();
6 for ( int i = 0 ; i < dt.Columns.Count; i ++ )
7 {
8 dgvfinance.Columns.Add(dt.Columns[i].ColumnName, dt.Columns[i].ColumnName);
9 }
10 DataGridViewRow row = null ;
11 for ( int i = 0 ; i < dt.Rows.Count; i ++ )
12 {
13 row = new DataGridViewRow();
14 for ( int j = 0 ; j < dt.Columns.Count; j ++ )
15 {
16 row.Cells.Add( new DataGridViewTextBoxCell());
17 }
18 row.SetValues(dt.Rows[i][ " 商户 " ], dt.Rows[i][ " 姓名 " ], dt.Rows[i][ " 栏目名称 " ], dt.Rows[i][ " 交易时间 " ], dt.Rows[i][ " 交易金金额 " ], dt.Rows[i][ " 交易后剩余金额 " ], dt.Rows[i][ " 备注 " ]);
19 dgvfinance.Rows.Add(row);
20 }
21 }
22

你可能感兴趣的:(datagridview)