• 关于获取c# 的winform中DataGird控件选中行的值


    注,使用时需要先判断this.dataGridView1.SelectedCells.count,不为0 在进行上面的操作。

    获取总行数:dataGridView1.Rows.Count;
    获取当前选中行索引:int i = this.dataGridView1.CurrentRow.Index;
    获取当前选中列索引:int j = this.dataGridView1.CurrentCell.ColumnIndex;

    方法一:

    this.dgvStuList.SelectedRows[0].Cells["列"].Value.ToString()

    方法二:

    dgvStuList.Rows[dgvStuList.CurrentRow.Index].Cells["列名"].Value.ToString()

    /////////////////////////////////////////////////

    点击已有数据行时只允许修改和删除,不可以添加,点击空白行时只运行添加,不允许删除和修改,那问题是如何来判断用户点击的是空白行呢,按钮是否可用的判断代码放在哪里呢?

    解决方法:给datagrid添加mouse_enter事件

    private void userInfo_MouseEnter(object sender,System.EventArgs e)   {    
    int row = userInfo.CurrentCell .RowNumber;    
    if(row == list.Size)           //list 是我用来存放数据表的对象集合,    {     
    menu.MenuItems[0].Enabled = true;    
    }    
    else    
    {     
    menu.MenuItems[0].Enabled = false;    
    }

    }
    本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/guoguo19811025/archive/2008/06/18/2561141.aspx

    ///////////////////////////////////////////////////////////

  • 相关阅读:
    linux 硬件信息
    docker note
    Shell cmd set note
    mysql management note
    scp noneed passwd
    update kernel
    数据包处理过程
    tcp/ip分片
    sockopt note
    Python note
  • 原文地址:https://www.cnblogs.com/wuhuisheng/p/2019931.html
Copyright © 2020-2023  润新知