Click here to Skip to main content
15,891,033 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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.

C#
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;

    }
}
Posted

1 solution

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.
 
Share this answer
 
Comments
TarikHuber 27-Apr-14 9:05am    
I want to bind a DataGridView Column to an Control and to call the same Event if a DataGridView Cell from the Column is validated or the bound Control to the Column is validated.
aboubkr90 7-May-14 23:11pm    
Sorry for the late response -_-
If i understood you right, You are trying to call CellValidated when the control is validated, A way to do that would be to add a Validated event handler to the control (when bound) that finds its corresponding cell and calls CellValidated on it.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900