zoukankan      html  css  js  c++  java
  • 右键删除行

    右键

    ContextMenustrip

    删除行

    DataGridview1.Rows.RemoveAt(行索引值);

    private void Form1_Load(object sender, EventArgs e)
            {
                string constr = "server=192.168.100.222;uid=sa;pwd=p@ssw1rd;database=pwd1";
                SqlConnection mycon = new SqlConnection(constr);
                DataTable mytb = new System.Data.DataTable();
                mycon.Open();
                SqlDataAdapter mydapt = new SqlDataAdapter("select * from book",mycon);
                mydapt.Fill(mytb);
    
                dataGridView1.DataSource = mytb;
    
            }
            //鼠标键抬起时
            privatevoiddataGridView1_CellMouseUp(objectsender,DataGridViewCellMouseEventArgs e)
            {
                if (e.Button==MouseButtons.Right)
                {
                    //右键选择当前行
                    this.dataGridView1.Rows[e.RowIndex].Selected = true;
                    //当前单元格唯一
                    this.dataGridView1.CurrentCell = dataGridView1.Rows[e.RowIndex].Cells[0];
                    //显示右键菜单(在datagridview中的e.location位置显示)
                    this.contextMenuStrip1.Show(dataGridView1,e.Location);
                    //显示右键菜单在鼠标的位置显示
                    this.contextMenuStrip1.Show(Cursor.Position);
                }
                
            }
    右键删除行.
            private void Form1_Load(object sender, EventArgs e)
            {
                string constr = "server=192.168.100.222;uid=sa;pwd=p@ssw1rd;database=pwd1";
                SqlConnection mycon = new SqlConnection(constr);
                DataTable mytb = new System.Data.DataTable();
                mycon.Open();
                SqlDataAdapter mydapt = new SqlDataAdapter("select * from book",mycon);
                mydapt.Fill(mytb);
    
                dataGridView1.DataSource = mytb;
    
            }
            //鼠标键抬起时
            private void dataGridView1_CellMouseUp(object sender, DataGridViewCellMouseEventArgs e)
            {
                if (e.Button==MouseButtons.Right)
    	        {
                    //右键选择当前行
                    this.dataGridView1.Rows[e.RowIndex].Selected = true;
                    //当前单元格唯一
                    this.dataGridView1.CurrentCell = dataGridView1.Rows[e.RowIndex].Cells[0];
                    //显示右键菜单(在datagridview中的e.location位置显示)
                    this.contextMenuStrip1.Show(dataGridView1,e.Location);
                    //显示右键菜单在鼠标的位置显示
                    this.contextMenuStrip1.Show(Cursor.Position);
    	        }
                
            }
    
  • 相关阅读:
    2021.2.5 学习总结
    2021.2.1 学习总结
    2021.2.4 学习总结
    学习:C#中struct与class的区别(转)
    学习:DirectoryEntry::Path 属性(winnt、LDAP、IIS)(转)
    学习:Asp.net页面传值总结(转)
    学习:WinForm分页控件(转)
    学习:c#中抽象类和接口的相同点跟区别(转)
    学习:C#中获取当前路径的几种方法(转)
    记录:new关键字、new修饰符、new约束
  • 原文地址:https://www.cnblogs.com/xiaowie/p/8651653.html
Copyright © 2011-2022 走看看