zoukankan      html  css  js  c++  java
  • WinForm DataGridView根据选中的行多删

             private void btndel_Click(object sender, EventArgs e)
            {
                int count = 0;
                //获取选中的行数
                count = this.dataGridView1.SelectedRows.Count;
                if (count == 0)
                {
                    MessageBox.Show("至少选择一项!!", "提示");
                    return;
                }
                DialogResult dr = MessageBox.Show("共"+count+"条,确定要删除吗?","警告",MessageBoxButtons.YesNo,MessageBoxIcon.Information);
                if(dr==DialogResult.Yes)
                {

                    string str = "";
                    //循环选中的行并获取想要的值
                    foreach (DataGridViewRow row in dataGridView1.SelectedRows)
                    {
                        str += row.Cells[0].Value.ToString()+",";
                    }
                    if (str.Length > 0)
                    {
                        str = str.Substring(0, str.Length - 1);
                    }
                    StudentBLL bll = new StudentBLL();
                    //调用删除的方法
                    if (bll.DelStudent(str) > 0)
                    {
                        MessageBox.Show("删除成功", "提示");
                        StudentShow();//刷新数据
                    }
                    else
                    {
                        return;
                    }
                }

  • 相关阅读:
    List<T>Find方法,FindAll方法,Contains方法,Equals方法
    C#SerialPort如何读取串口数据并显示在TextBox上
    49、css属性相关
    40、协程
    45、mysql 储存过程
    37、进程之间的通信
    38、线程及其方法
    39、多线程和线程池
    33、验证客户端的合法性、socketserver模块
    32、黏包的解决方式、struct模块
  • 原文地址:https://www.cnblogs.com/ZHANGKAIXUAN/p/6097901.html
Copyright © 2011-2022 走看看