Word Custompane: failed to display the DataGridView control which ColumnHeadersHeight is adjust RRS feed

  • Question

  • Question:

    Environment: win10 + office2016 word (version201906 16.0.11727.20222)  32bit or 64bit  

    Create a new custompane by pressing the button of the custom mean tab (the subsequent description is Method 2). There is a DataGridView control on the custompane. If you adjust the ColumnHeadersHeight of the DataGridView control ,it will not be able to display the control.

    Contrast directly to create a new custompane in ThisAddIn_Startup funtion, identically there is a DataGridView control on the custompane, and adjust the ColumnHeadersHeight of the DataGridView control, which can be displayed normally (subsequent expression is Method 1);

    At the same time, we also found an association problem: If method 1 and method 2 are in the same wordAddin program, method 1 creates a new custompane and adjusts the ColumnHeadersHeight. Then the new panel of method 2 adjusts the height of the header at the same time. it will be Normal display;  If the method1 creates a new custompane,but the ColumnHeadersHeight is not adjusted, then method 2 creates a new custompane, identically the ColumnHeadersHeight is adjusted, it cannot be displayed;

    // UserControl1.Designer.cs or UserControl2.Designer.cs 
    // this.dataGridView1.ColumnHeadersHeight = 100;
    namespace WordAddInTest
        partial class UserControl1
            private void InitializeComponent()
                this.dataGridView1 = new System.Windows.Forms.DataGridView();
                this.Column1 = new System.Windows.Forms.DataGridViewTextBoxColumn();
                this.Column2 = new System.Windows.Forms.DataGridViewTextBoxColumn();
                // dataGridView1
                this.dataGridView1.ColumnHeadersHeight = 100; // attention this code,it will impact the display 
                this.dataGridView1.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] {
                this.dataGridView1.Location = new System.Drawing.Point(120, 257);
                this.dataGridView1.Name = "dataGridView1";
                this.dataGridView1.RowTemplate.Height = 37;
                this.dataGridView1.Size = new System.Drawing.Size(558, 557);
                this.dataGridView1.TabIndex = 0;

    // ThisAddIn.cs
    // creats a custompane in ThisAddIn_Startup  
    // UserControl1 UserControl2 has same code In addition to whether to adjust 
    // this.dataGridView1.ColumnHeadersHeight
     private void ThisAddIn_Startup(object sender, System.EventArgs e)
    public void CreateUserControl()
                UserControl1 ucl = new UserControl1();
               Microsoft.Office.Tools.CustomTaskPane pane = Globals.ThisAddIn.CustomTaskPanes.Add(ucl, "Add-in1");
                pane.Visible = true;

    // Ribbon1.cs // through add Ribbon1.cs to create a menu tab, and this tab has a DisplayPane button; // in the DisplayPane'Click eventfuntion to add the custompane private void BTN_DisplayPane_Click(object sender, RibbonControlEventArgs e) { UserControl2 ucl = new UserControl2(); Microsoft.Office.Tools.CustomTaskPane pane = Globals.ThisAddIn.CustomTaskPanes.Add(ucl, "Add-in2"); pane.Visible = true; }

    the custompane add-in1_1 addin1_2 are created by add-in1.dll
    the customnpane add-in2_1 addin2_2 are created by add-in2.dll

    the custompane add-in1_1 and add-in2_1 are created by ThisAddIn_Startup funtion, add-in1_1' UserControl adjust ColumnHeadersHeight to 100; For comparison add-in2_1 is not adjust

    the custompane addin2_1 and addin2_2 are created by the menu tab's DisplyPane button; Both of them adjust ColumnHeadersHeight to 100; 

    result: the custompane addin2_2' DataGridView control is not to display.

    my account has not be verify, so I dont't contain image or links; when my account verified, i will add image by the first time~

    • Edited by kevin_Mei Monday, July 29, 2019 9:51 AM
    Monday, July 29, 2019 2:56 AM

All replies

  • Hello Kevin,

    I'd suggest specifying the third argument. To determine which window displays the custom task pane, use the appropriate Add method overload when you create the task pane:

    • To associate the task pane with the active window, use the Add method.

    • To associate the task pane with a document that is hosted by a specified window, use the Add method.

      Some Office applications require explicit instructions for when to create or display your task pane when more than one window is open. This makes it important to consider where to instantiate the custom task pane in your code to ensure that the task pane appears with the appropriate documents or items in the application. For more information, see Manage custom task panes in application windows.

    profile for Eugene Astafiev at Stack Overflow, Q&A for professional and enthusiast programmers

    Monday, July 29, 2019 3:53 AM
  • Hi Eugene:

    First, thank you for whaching my problem, and I think I don't pass the Accurate message in my first description;  the result is the custompane 's datagradview control is not display,Instead of the custompane itself; when I creat a custompane by  the custom menu tab's Disply Pane button,   if  i adjust the datagradview's ColumnHeadersHeight , the datagradview control is not dispaly; else i don‘t adjust the datagradview's ColumnHeadersHeight, it will be dispaly;  both of them can dispaly the custompane, only the datagradviewcontrol is display or not;

    when the WORD  updated  about 20190628 (version 16.0.11727.20222), so this problem is occur; when I uninstall the word, then reinstall the WORD, and keep the WORD doesn't update,  this problem is not exist, everything is ok; so I guess This problem is caused by this update;

    Could you can give some suggestion?  Thank you very much~

    • Edited by kevin_Mei Monday, July 29, 2019 9:58 AM
    Monday, July 29, 2019 9:45 AM
  • hope somebody can solve my problem, I will concert  untill it solved~
    Thursday, August 22, 2019 2:23 AM