首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > C# >

winform_dataGridView更新有关问题,多谢

2012-01-29 
winform_dataGridView更新问题,谢谢!为什么这样可以,注释的那部分方法不行?出错。谢谢回答。intjdataGridVi

winform_dataGridView更新问题,谢谢!
为什么这样可以,注释的那部分方法不行?出错。谢谢回答。
                        int   j   =   dataGridView1.SelectedRows.Count;
                        int[]   l   =   new   int[j];

                        int   i;
                        for   (i   =   0;   i   <   j;   i++)
                        {
                                l[i]   =   dataGridView1.SelectedRows[i].Index;
                        }

                        int   k   =   0;
                        while   (k   <   j)
                        {
                                this.northwindDataSet.Customers.Rows[l[k]].Delete();
                                k++;
                        }
                        //this.customersTableAdapter.Update(this.northwindDataSet.Customers);

                        //int   count   =   dataGridView1.SelectedRows.Count;
                        //for   (int   i   =   0;   i   <   count;   i++)
                        //{
                        //         this.northwindDataSet.Customers.Rows.RemoveAt(dataGridView1.SelectedRows[i].Index);
                        //}
                        //foreach   (DataGridViewRow   dr   in   dataGridView1.Rows)
                        //{
                        //         if   (dr.Selected)
                        //         {
                        //                 this.northwindDataSet.Customers.Rows[dr.Index].Delete();
                        //         }
                        //}
                        try
                        {


                                this.customersTableAdapter.Update(this.northwindDataSet.Customers);
                        }
                        catch   (Exception   e1)
                        {
                                MessageBox.Show(e1.Message);
                        }


[解决办法]
如果用for 删掉后一项后其它的项的index会变 继续使用i不行的
如果用foreach 不允许修改其成员

热点排行