• DataGridView属性和事件


            //注册绑定事件
            private void dgvBidFile_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e)
            {
                DataGridView dataGridView = (DataGridView)sender;
                int columnIndex = dataGridView.CurrentCell.ColumnIndex;
    string columnName = dataGridView.Columns[columnIndex].Name; //获取某一列的名称
    if (columnName== "colId"||columnName=="colName"||columnName=="colAge") { e.Control.KeyPress += new KeyPressEventHandler(TextBoxDec_KeyPress); } if (dataGridView.CurrentCell.GetType().Name == "DataGridViewComboBoxCell") { bidFileId = Convert.ToInt32(dataGridView.CurrentRow.Cells[this.colBidFileId.Index].Value); ComboBox comboBox = (ComboBox)e.Control; comboBox.SelectedIndexChanged += new EventHandler(this.comboBox_SelectedIndexChanged); } } //只输入数字判定事件。该事件是手动添加的绑定事件 private void TextBoxDec_KeyPress(object sender, KeyPressEventArgs e) { if (e.KeyChar != 8 && !Char.IsDigit(e.KeyChar) && e.KeyChar != '.') { e.Handled = true; } } //下拉框更改事件,该事件是手动添加的绑定事件 private void comboBox_SelectedIndexChanged(object sender, EventArgs e) { ComboBox comboBox = (ComboBox)sender; //接下来获取下来框中的内容... //comboBox.Text为当前选定的下拉框的内容 } //普通文本框更改事件 private void dgvBidFile_CellValueChanged(object sender, DataGridViewCellEventArgs e) { if (e.ColumnIndex == this.colRemark.Index) { //colRemark为数据绑定列 //发生什么事... } }
     //默认值,添加新行时才会触发。dgv必须选中启用添加,并且是用户鼠标进入带*的新行才会触发
    private void dgvBidFile_DefaultValuesNeeded(object sender, DataGridViewRowEventArgs e)
    {
          e.Row.Cells["coId"].Value = 1;
          e.Row.Cells["colName"].Value = "你好";
    }
  • 相关阅读:
    PHP压缩html网页代码 : 清除空格,制表符,注释标记
    CentOS 编译 Nginx 服务
    Fedora 下安装Fcitx输入法
    SVN 脚本
    Linux 在线播放
    Linux命令行下常用svn命令
    linux vi(vim)常用命令汇总
    MySQL修改root密码
    Fedora 查看CHM帮助文档
    Fedora 快捷键
  • 原文地址:https://www.cnblogs.com/AlexOneBlogs/p/8384033.html
Copyright © 2020-2023  润新知