我在页面加载事件中动态地在datagridview中添加数据。但是我收到一个错误,指出索引超出范围。 (“必须为非负且小于DataGridView中collection.parameter名的大小。”)指数超出范围。必须是非负数,并且小于datagridview中collection.parameter名称的大小?
以下是代码:
dataGridView1.Rows.Add();
dataGridView1.Rows[0].Cells[0].Value = "Basic";
dataGridView1.Rows[0].Cells[1].Value = "Basic";
dataGridView1.Rows[1].Cells[0].Value = "PDALLW";
dataGridView1.Rows[1].Cells[1].Value = "Professional Development Allow";
dataGridView1.Rows[2].Cells[0].Value = "BPAllw";
dataGridView1.Rows[2].Cells[1].Value = "Business Promotion Allowance";
您在这里使用3行,但只添加一行。也许这是问题? – 2012-08-09 13:11:23
这是绑定到DataGrid的好链接。 http://stackoverflow.com/questions/5809816/datagrid-binding-in-wpf – Omzig 2012-08-09 13:13:12