zoukankan      html  css  js  c++  java
  • C#——dataGridView控件获取当前鼠标所在的行

    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 row = dataGridView1.CurrentCellAddress.Y + 1;
                int col=dataGridView1.CurrentCellAddress.X+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+"行;"+col+"列
    内容是:"+cell);
            }
  • 相关阅读:
    cd的使用
    转换器模式
    装饰模式
    策略模式
    模板方法模式
    工厂模式
    类型信息
    proto编译组件使用
    proto编译引用外部包问题
    Kafka经典三大问:数据有序丢失重复
  • 原文地址:https://www.cnblogs.com/eve612/p/14420913.html
Copyright © 2011-2022 走看看