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);
    
    
                }
             
            }
        }
    }
  • 相关阅读:
    php-管理变量
    php-变量的间接引用
    php-eval()
    HTML
    php观
    笔记1
    脚本语言
    Windows Server 2012如何把快捷方式加到启动文件夹中
    VIM的笔记
    mongodb 从3.0 升级到3.2
  • 原文地址:https://www.cnblogs.com/zqyo2000z/p/5401308.html
Copyright © 2011-2022 走看看