Search code examples
c#.netcustom-controlsinfragisticsultrawingrid

Create UserControl By using UltraGrid of Infragistics


I want to create a custom control using Infragistics UltraGrid control. I want to add a button on top of the UltraGrid which exports data as excel. You can get better idea by viewing below image.

enter image description here

This grid is used many times in my project so that i need it in a user control. I have tried to create it but when i add this control in my project i cannot access all actual properties of that UltraGrid.

please help...


Solution

  • You are creating a composite control. Normally this means that you can't access the composing controls from the form where you want to position your usercontrol. Usually you need to provide the code to access the underlying properties and events of the controls that compose your UserControl.

    For example, supposing that you want to change the caption of the UltraWinGrid inside your user control, you should write a get/set property like this in the code of the UserControl.

    public string GridText
    {
        get
        {
            return ultraGrid1.Text;
        }
        set
        {
            ultraGrid1.Text = value;
        }
    }
    

    As you can imagine, this is not a trivial task with a control like the Infragistics UltraWinGrid that has probably thousands of properties. Not to mention the long list of events.

    See here a tutorial from Microsoft about building a Composite Control and that explain the problem with properties of the underlying controls.

    A simple workaround (NOT RECOMMENDED) could be to change the property Modifiers of the UltraWinGrid and of the button from Private to Public. In this way the grid reference is available from the properties of the UserControl and you can program it as before.

     userControl1.ultraGrid1.Text = "My User Control";
    

    However this is not recommended because you give full access to the composing controls and this, in certain situations, could be not desiderable. It largely depends on your using scenario.