zoukankan      html  css  js  c++  java
  • 15.3获取DataGridView的当前单元格的索引和内容

    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._3DataGridView单元格
    {
        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 void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
            {
                //获取行列索引
                //第一种方式
                //int row = e.RowIndex + 1;
                //int col = e.ColumnIndex + 1;
    
                //第二种方式
                //int row = dataGridView1.CurrentCell.RowIndex + 1;
                //int col = dataGridView1.CurrentCell.ColumnIndex + 1;
    
                //第三种方式
                int col = dataGridView1.CurrentCellAddress.X+1;
                //int row = dataGridView1.CurrentCellAddress.Y+1;
    
                //第四种方式行的引用
                int row = dataGridView1.CurrentRow.Index+1;
    
                //获取单元格的内容
                //1种方法
                //string cell = dataGridView1.Rows[row-1].Cells[col-1].Value.ToString();
                //2种方法
                string cell = dataGridView1.CurrentCell.Value.ToString();
    
    
    
                MessageBox.Show("您点击的是:第"+row.ToString()+"行,第"+col.ToString()+"列,内容为:"+cell);
            }
        }
    }
  • 相关阅读:
    MYSQL profiling分析语句
    进程状态与僵尸进程、孤儿进程
    Nginx跨域设置
    Redis的应用场景
    Nginx的作用
    cgi、fast-cgi和php-fpm的介绍(作用)
    CoreDump开启和Swoole Tracker 3.0配置
    好题总结
    Atcoder总结 Part III
    Atcoder总结 Part II
  • 原文地址:https://www.cnblogs.com/zqyo2000z/p/5365024.html
Copyright © 2011-2022 走看看