views:

56

answers:

2

In our application, we are going to have several finder dialogs. The UI of a finder dialog is simple (text box, datagridview result, ok button, cancel button). The only real change between the different dialogs is some label text and the grid binding source. We want to enforce certain properties (like full row selection and read only mode) and events (like click and double click) so that when someone wants to add a dialog, we know that the user will get consistent behavior because that dialog implements the same properties and events that every other dialog in our application implements.

I created a base finder form that hosts some properties and the ok/cancel buttons + their click events. I'm stuck on the datagridview. What would be the best approach to ensure that all the datagridviews share similar characteristics when on one of our finder dialogs?

+2  A: 

If the only difference between the different dialogs are the text of some label and the binding source of the datagridview, why not simply use the same form for all the dialogs? You can easily have the form expose properties through which you can control those differencies.

Fredrik Mörk
I don't want to loose some of the visual studio design time stuff you get when setting a binding data source on a grid. Perhaps I should create a grid that descends from DataGridView and enforce these properties and methods.
Coov
A: 

Today I implemented a custom grid (DataGridViewFinder) that descends from DataGridView. This grid is specific to our finder dialogs only. The grid has default properties set so that it is consistent with all of our other finder grids. Also, because I know that this type of grid will only be on a finder dialog, I've overridden some events that will set properties and call methods on the base finder.

I like this approach because it ensures that when I drop my custom grid on a finder dialog, that certain properties and events are already handled for me. There will be many finder dialogs and I suspect this will save a lot of time. Does anyone see anything wrong with this implementation?

protected override void OnEnter(EventArgs e)
{
    base.OnEnter(e);
    if (Parent is BaseFinder)
    {
        (Parent as BaseFinder).Mode = FinderMode.Ok;
    }
}

protected override void OnDoubleClick(EventArgs e)
{
    base.OnDoubleClick(e);
    if (Parent is BaseFinder)
    {
        (Parent as BaseFinder).btOk_Click(this, e);
    }
}
Coov