dataGridView怎么循环增加多行


C# code public void LoadDataGridViewData(DataGridView view, DataTable table) { view.Rows.Add(20); int index = 0; foreach (DataRow row in table.Rows) { DataGridViewRow viewRow = view.Rows[index]; for (int j = 0; j < view.Columns.Count; j++) { if (!String.IsNullOrEmpty(view.Columns[j].DataPropertyName) && row.Table.Columns.Contains(view.Columns[j].DataPropertyName)) viewRow.Cells[j].Value = row[view.Columns[j].DataPropertyName]; } index++; } } LoadDataGridViewData(dataGridView1, dt); ------解决方案--------------------------------------------------------view.Rows.Add(20)改成view.Rows.Add(40),外面再套一个for循环,像你写的那样就行了 ------解决方案--------------------------------------------------------C# code DataTable dt = new DataTable(); for(int i=0;i