views:

25

answers:

1

This is a winform C# question.

I have a customized DataGridView control inherited from the standard DataGridView class. I want to monitor the case whenever a cell is added to the grid, a cell value is changed in the grid. I have no idea how to do this.

The DataBindingCompleted event is helpless in cell/row/column level. The CellValueChanged event is confusing itself since it is only fired when user modifies a value from UI and is helpless if the value is updated from underlying data source. What is the proper event to listen to? I know DataGridViewCell class has a ValueChanging event. But in the customized DataGridView, how can I hook my event listener to every cell? Thanks for the help.

A: 

In your custom control, you need a global event variable:

public event EventHandler CustomCellValueChanged;

you need to set the cell changed event with this:

    private void gvGridView_CellValueChanged(object sender, EventArgs e)
    {
        EventHandler Handler = CustomCellValueChanged;
        if (Handler != null) { Handler(this, e); };
    }

Then in your form, you will be able to check the event CustomCellValueChanged

Wildhorn
This does not solve the original problem. It creates a redundant copy of CellValueChanged which serves no purpose, since the subclass will still provide access to the original event. It does not fire when cells are added to the grid, as the author of the question specified.
Bradley Smith
Agree with Bradley. But still thank you for the effort.
Steve
Ah sorry, read wrong the question. My bad.
Wildhorn