Hey guys,

I'm trying to design a custom control to extend a datagridview.
The customer control is basically made up of two datagridviews, one will host the extra features, the second will offer all the usual methods/events of a regular datagridview.

What i want to know is, can i automatically pass incoming method calls to the sub control and pass raised events out without manually writing the methods.

For example, i can manually add a property like so:

public bool AllowUserToOrderColumns
        {
            get { return dgvTable.AllowUserToOrderColumns; }
            set { dgvTable.AllowUserToOrderColumns = value; }
        }

So when a user sets the AllowUserToOrderColumns on my control the value is set on the childcontrol. Obviously i can do the same for events, if the child grid raises an event i can raise an event in my parent.

The problem is, there are hundreds of members that would need to be handled. Is there a way to automate it? Or am i coming at this completely the wrong way?

The automatic properties only work for simple get and set methods, because i have to pass the data to and from the child control i dont think they will work.
The same goes for overriding, overriding allows you to replace the functionality of a control, i need to access its functionality : /

I've got a horrid feeling it will require a lot of manual coding :'(

I'm not sure I understand your design here. It sounds like you're talking about creating a class that inherits from a grid view but it also sounds like you're encapsulating the class. Can you post code samples?

Sorry for late response, my stupid body is determined to hold me back...maybe Santa can make me better for christmas haha.

What im trying to do is solve the issue of multicolumn headers in a datagridview. I did it manually on a recent project by placing a dgv for the headers directly above the main dgv. I then synced the ColumnSizeChagned and Scroll events between them. Worked great so I wanted to put this together as a single control. Im fairly new at custom controls, so i'm a little lost.
Ive created the User Control project and added the two dgv's in the designer. The problem is, i would really like to forward any of the standard datagridview method calls etc straight to the main dgv.
Not sure im describing this very well, sorry, brain is a bit fuzzy today. The following pseudocode kinda shows the structure i'm going for, the attached picture is the designer view.

extendedDGV : User Control
{
      Headers : DataGridView
      {
      }
      Body : DataGridView
      {
      }
}

What i would like to do is have it so that if the application calls (for example) extendedDGV.AllowUserToAddRows it gets forwarded to Body.AllowUserToAddRows.

I've started doing this with properties:

public bool AllowUserToAddRows
        {
            get { return dgvBody.AllowUserToAddRows; }
            set { dgvBody.AllowUserToAddRows = value; }
        }

But there would literally be hundreds of properties to hand type if i do it this way : /

Attachments dgv.JPG 15.8 KB

Can you upload an application with your customizations? A user control forces you to encapsulate or expose the class members as public properties. It is really hard to determine a design approach without seeing what changes you have made.

I dont have an application i can upload at present. The app i did it in recently, i cant really share and my attempt thus far at a user control consists of two datagridviews on the designer. I think i'm just gonna shelve it until i have time to read up properly on designing user controls and i can give it the proper attention :)

Thanks for the suggestions guys.

I believe I understand what you want, and I don't think it is possible with user control. I have also wanted to create custom controls utilizing UserControl without the need to manually expose each of the methods and properties of the container controls. If and when you figure it out, please share.;)

Why not extend the grid, not the user control? Refer to the code snippet Danny posted: http://www.daniweb.com/code/snippet217338.html

The class he coded up inherits directly from the CheckBox instead of creating a user control to house the checkbox. This might be possible with what you're doing ... depending on how the grids interact.

This question has already been answered. Start a new discussion instead.