zoukankan      html  css  js  c++  java
  • 15.5DataGridView右键删除当前行

    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using System.Windows.Forms;
    
    namespace _15._5DataGridView右键删除行
    {
        public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();
            }
    
            private void Form1_Load(object sender, EventArgs e)
            {
                // TODO: 这行代码将数据加载到表“csharpzxwDataSet.mytable001”中。您可以根据需要移动或删除它。
                this.mytable001TableAdapter.Fill(this.csharpzxwDataSet.mytable001);
    
            }
            private int rowIndex = 0;//定义一个全局变量,以便删除行方法可以访问的到
            private void dataGridView1_CellMouseUp(object sender, DataGridViewCellMouseEventArgs e)
            {
                if (e.Button == MouseButtons.Right)//判断是否当前弹起的右键
                {
                    rowIndex = e.RowIndex;
                    this.dataGridView1.Rows[e.RowIndex].Selected = true;//选中鼠标所在的当前行
                    this.dataGridView1.CurrentCell = this.dataGridView1.Rows[e.RowIndex].Cells[1];//默认当前单元格为第一行第一个
                    //this.contextMenuStrip1.Show(this.dataGridView1, e.Location);//右键菜单绑定当前位置,也就是第一行第一个
                    contextMenuStrip1.Show(Cursor.Position);
                }
            }
    
            private void 删除行ToolStripMenuItem_Click(object sender, EventArgs e)
            {
                if (!this.dataGridView1.Rows[this.rowIndex].IsNewRow) //判断当前行是否为空行
                {
                    this.dataGridView1.Rows.RemoveAt(rowIndex);
    
    
                }
             
            }
        }
    }
  • 相关阅读:
    基本概念和术语
    Html中的<label>标签
    shell17echo打印带颜色的文字
    shell-15 &的三种不同
    shell-14 多个命令以分号隔开
    shell-13 tee管道可以重定向但是不截流
    shell-12实用cat完成文件复制
    shell-11输入内容到文件
    shell-10kill杀死作业号和进程号
    shell-9前后台切换
  • 原文地址:https://www.cnblogs.com/zqyo2000z/p/5401308.html
Copyright © 2011-2022 走看看