zoukankan      html  css  js  c++  java
  • dataGridView 控件快速绑定数据源后,简单的代码实现


    private void dataGridView_Kuaidi_RowLeave(object sender, DataGridViewCellEventArgs e)
    {
    // 注意下面四局缺一不可,
    this.Validate(); // 如果没有这句话,最后一个单元格的编辑,不会提交
    this.kuaidiBindingSource.EndEdit();
    int nUpdatedRows = this.kuaidiTableAdapter.Adapter.Update(this.clothesShopDataSet);

    clothesShopDataSet.AcceptChanges(); // 由于随后要对数据库操作,没有这句话会报错:“违反并发性 UpdateCommand 影响了预期1条记录中的0条”
    }

    private void dataGridView_Kuaidi_CellContextMenuStripNeeded(object sender, DataGridViewCellContextMenuStripNeededEventArgs e)
    {
    if (e.ColumnIndex < 0)
    {
    // 行头的ContextMenuStrip设定
    e.ContextMenuStrip = this.contextMenuStrip1;
    dataGridView_Kuaidi.CurrentCell = dataGridView_Kuaidi[0, e.RowIndex];
    }
    }

    private void ToolStripMenuItem_Del_Click(object sender, EventArgs e)
    {
    int CurrentRowIndex = dataGridView_Kuaidi.CurrentCell.RowIndex;
    DataGridViewRow row = dataGridView_Kuaidi.Rows[CurrentRowIndex];
    dataGridView_Kuaidi.Rows.Remove(row);

    //防止滚动条滚到不是想要到的地方。
    dataGridView_Kuaidi.CurrentCell = dataGridView_Kuaidi[0, CurrentRowIndex];
    }

    private void dataGridView_Kuaidi_UserDeletingRow(object sender, DataGridViewRowCancelEventArgs e)
    {
    if (!e.Row.IsNewRow)
    {
    DialogResult response = MessageBox.Show("确定删除该行?", "删除行?",
    MessageBoxButtons.YesNo,
    MessageBoxIcon.Question,
    MessageBoxDefaultButton.Button2);
    if (response == DialogResult.No)
    e.Cancel = true;
    }
    }

  • 相关阅读:
    [Winform]Media Player com组件应用中遇到的问题
    [Winform]Media Player播放控制面板控制,单击事件截获
    [Winform]Media Player组件全屏播放的设置
    [EF]数据上下文该如何实例化?
    [Winform]在关闭程序后,托盘不会消失的问题
    咏南中间件跨平台解决方案
    硬件中间件
    BASE64使用场景
    DELPHI7 ADO二层升三层新增LINUX服务器方案
    NGINX心跳检测
  • 原文地址:https://www.cnblogs.com/carl2380/p/2679854.html
Copyright © 2011-2022 走看看