c# DataGridView 批量选中行删除函数

Posted on 2010-11-30 20:52  严武  阅读(2810)  评论(0编辑  收藏  举报

      private void MulDelete()
        {
            long[] long_id = new long[100];
            int[] int_id = new int[100];
            int k = 0;
            for (int i = 0, mk = 0; i < dataGridv_AdminIma.Rows.Count; i++, mk++)//循环遍历DataGridView控件中的每一行
            {
                if (dataGridv_AdminIma.Rows[i].Selected == true)
                {
                    string s = string.Empty;
                    try
                    {
                        s = dataGridv_AdminIma.Rows[i].Cells[0].Value.ToString();
                    }
                    catch (Exception)
                    {

                        s = string.Empty;
                    }
                    if (s != string.Empty)
                    {
                        //ExcisionData(s);//执行删除操作
                        long_id[k] = Convert.ToInt64(s);
                        int_id[k] = mk;
                        k++;
                        mk--;
                     

                    }

                }
            }

 

            bool Resualt = BLL.Delete(long_id, k);  //对数据库批量删除操作


            if (Resualt == false)
            {
                MessageBox.Show("删除失败.", "系统提示");
            }

 

            for (int j = 0; j < k; j++)
            {
                dataGridv_AdminIma.Rows.RemoveAt(int_id[j]);//移除处于选定状态的记录

            }
        }

Copyright © 2024 严武
Powered by .NET 9.0 on Kubernetes