Creating a DataGridView on a Winform designer isn't serializing properly RRS feed

  • Question

  • I am writing a Visual Studio integration package with a custom tool window. The tool window helps the user build GUIs by creating pre-configured controls, but I can't seem to get the DataGridView control to work properly.

    I am using IDesignerHost.CreateComponent(typeof(DataGridView)) to create a grid control on the surface of a winform designer, in Visual Studio 2008. I then programmatically configure the grid, including adding several columns. The designer.cs updates with the appropriate code, except for the column information. I've tried to coax the designer into serializing the column setup code into the designer.cs file:

                IComponentChangeService iccs = (IComponentChangeService)GetActiveDesigner().GetService(typeof(IComponentChangeService));

                iccs.OnComponentChanged(grid, TypeDescriptor.GetProperties(grid)["Columns"], null, grid.Columns);

    but nothing seems to work. Of course, if I add the columns the normal way, through the property grid, everything serializes properly. What is the IDE doing that I'm not?



    Tuesday, March 17, 2009 3:29 AM


  • Hi, Aaron

    Have you called 
    OnComponentChanging first?

    On MSDN about
    Before calling OnComponentChanged, first call OnComponentChanging to indicate that a component is about to change, and make the change. Then call OnComponentChanged to raise the ComponentChanged event.


    Please mark the replies as answers if they help and unmark them if they provide no help.
    • Edited by Wesley Yao Thursday, March 19, 2009 7:57 AM typo
    • Marked as answer by Wesley Yao Monday, March 23, 2009 2:07 AM
    Thursday, March 19, 2009 7:56 AM