如何调用未知控件的验证事件? [英] How to Call the Validated Event of an unknown Control?

查看:71
本文介绍了如何调用未知控件的验证事件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Hy,我正在创建自己的Classes,用于将DataGridView绑定到DataSource,并将DGV的列绑定到Form控件。作品更加丰富,代码我将bigg发布在一个问题中。现在我试图绑定Control和DGV Cell事件。只有基本的,如验证,验证,点击等...



列是一个类kaled列,并列在列表kaled列中。 Column Class有像ColumnName这样的参数(用于标识DGV中的Column),Control witch代表Win Form中的实际控件。



现在我希望能够如果一个特定的Cell被验证调用了一个Method,并且如果父Control被验证调用了Same Method,那么我就不必为DGV和Control编写相同的代码了。



我正在搜索这样的东西。我知道它的错误,只是为了展示我在寻找的东西。



  public   void  CellValidating( object  sender,DataGridViewCellValidatingEventArgs e)
{
DataGridView dgv = sender as DataGridView;
DataGridViewRow row = dgv.Rows [e.RowIndex];
DataGridViewColumn column = dgv.Columns [e.ColumnIndex];
DataGridViewCell cell = row.Cells [e.ColumnIndex];
控制控件= ParentTable.Columns [e.ColumnIndex] .Control;

if (control!= null
{

control.Validated = ParentDataGrdiView.CellValidated;

}
}

解决方案

因为这是你自己的图书馆我不喜欢不知道你是否这样做了,但是......

通常发送者是验证控件,你需要调用验证

Hy, I´m making my own Classes for binding a DataGridView to a DataSource and binding The Columns of the DGV to Form Controls. The works greate and the code i to bigg to post it in one question. Now I´m trying to bind the Control and DGV Cell Events. Only the basic ones like Validated, Validating, Click etc...

The Column are bount over a Class kaled Column and listed in a List kaled Columns. The Column Class has Parameters like ColumnName (to identifie the Column in the DGV) and Control witch represents the actual control in the Win Form.

Now I want to be able that if a specific Cell is Validated that a Method is called and if the parent Control is Validated that the Same Method is called so I don´t have to write the same Code for DGV and Control.

I´m searching something like this. I know its wrong but just to demonstrate what I´m looking for.

public void CellValidating(object sender, DataGridViewCellValidatingEventArgs e)
{
    DataGridView dgv = sender as DataGridView;
    DataGridViewRow row = dgv.Rows[e.RowIndex];
    DataGridViewColumn column = dgv.Columns[e.ColumnIndex];
    DataGridViewCell cell = row.Cells[e.ColumnIndex];
    Control control = ParentTable.Columns[e.ColumnIndex].Control;

    if (control != null)
    {

        control.Validated = ParentDataGrdiView.CellValidated;

    }
}

解决方案

Since this is your own library I don't know if you did this, but...
Usually sender is the validating control and the one you need to call Validated on.


这篇关于如何调用未知控件的验证事件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆