事件如何相互调用

yanele 2013-04-09 03:37:03
有一个dataGridView1控件,写好了下面两个验让事件

private void dataGridView1_CellValidating(object sender, DataGridViewCellValidatingEventArgs e)
{
}

private void dataGridView1_RowValidating(object sender, DataGridViewCellCancelEventArgs e)
{
}


我想在dataGridView1_Leave事件中直接调用上面两个验证事件,该如何调用?主要不知道如何传入DataGridViewCellValidatingEventArgs 与DataGridViewCellCancelEventArgs 类.

private void myDataGridView1_Leave(object sender, EventArgs e)
{
dataGridView1_CellValidating(sender,?);
dataGridView1_RowValidating(sender,?);
}
...全文
96 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
夜轻风 2013-04-10
  • 打赏
  • 举报
回复
        private void dataGridView1_CellValidating(object sender, DataGridViewCellValidatingEventArgs e)
        {
            MessageBox.Show("111");
        }

        private void dataGridView1_RowValidating(object sender, DataGridViewCellCancelEventArgs e)
        {
            MessageBox.Show("222");
        }

        private void dataGridView2_Leave(object sender, EventArgs e)
        {
            this.dataGridView1_CellValidating(sender,e as DataGridViewCellValidatingEventArgs);
            this.dataGridView1_RowValidating(sender, e as DataGridViewCellCancelEventArgs);
        }
  • 打赏
  • 举报
回复
事件这样简单调用就可以了:


        private void button1_Click(object sender, EventArgs e)
        {
            this.button2_Click(sender, e);
        }

        private void button2_Click(object sender, EventArgs e)
        {
            MessageBox.Show("button2 has been clicked");
        }
yanele 2013-04-10
  • 打赏
  • 举报
回复
楼上的方法不报错了,但传入的e参数是null,跟踪执行到上面的方法里需要e.RowIndex判断就有问题了.
yanele 2013-04-09
  • 打赏
  • 举报
回复
不好意思,是WinForm程序,没有说清楚,主要不知道怎么传第二个参数.上面两个事件用到了e作为方法调用.
  • 打赏
  • 举报
回复
嗯,为什么不在前台写JS验证呢?

110,565

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧