c# datagridview 赋值

来源:百度知道 编辑:UC知道 时间:2024/05/15 10:36:50
我有两个数组,string[] a1;string[] a2现在这两个数组里都有数据。我想把数组a1中的数据付给datagridview的第一列,a2中的数据赋值给datagridview的第二列,应该怎么做???是windows程序

string[] a1 = new string[5] { "0", "1", "2", "3", "4" };
string[] a2 = new string[5] { "0", "1", "2", "3", "4" };

for (int i = 0; i < dataGridView1.ColumnCount; i++)
{
if (i > strs.Length) break;
dataGridView1.Rows[0].Cells[i].Value = a1[i];
dataGridView1.Rows[1].Cells[i].Value = a2[i];
}