Search code examples
c#winformsdatagridviewparenttabcontrol

Changing Contol Parent Removes Content


In my application, I have a DataGridView that moves from one Tab Control to another Tab Control.

I am doing this by changing its parent. This works with no problems on the first move from the origional Tab Control to the new one, but when changing the parent back to the origional, the DataGridView shows up (all the Columns are visible) but there is no data in the view.

I have tried to reload the data into the DataGridView, and refresh/Invalidate the control to make it redraw, but it still shows up empty. However, when the control goes back to the secondary parent, the data is back.

I am also using this exact code for another DataGridView and it works without any problems at all.

Any ideas would be greatly appreciated, and thanks in advance.

From Origional to Secondary

gvwRFIs.Parent = tabProcessingRFI; //Working
gvwConsentInfoMemos.Parent = tabProcessingMemos; //Working

From Secondary to Origional

gvwRFIs.Parent = tabConsentInfoRFI; //Empty Data
gvwConsentInfoMemos.Parent = tabConsentInfoMemos; //Working

RFI DataGridView Designer Code

        // 
        // gvwRFIs
        // 
        this.gvwRFIs.AllowUserToAddRows = false;
        this.gvwRFIs.AllowUserToDeleteRows = false;
        this.gvwRFIs.AllowUserToResizeRows = false;
        this.gvwRFIs.AutoSizeRowsMode = System.Windows.Forms.DataGridViewAutoSizeRowsMode.AllCellsExceptHeaders;
        this.gvwRFIs.BackgroundColor = System.Drawing.Color.White;
        this.gvwRFIs.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
        this.gvwRFIs.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] {
        this.gvwID,
        this.gvwType,
        this.gvwSeq,
        this.gvwCreated,
        this.gvwProcessor,
        this.gvwLetter,
        this.gvwResponded,
        this.gvwS,
        this.gvwDetails});
        this.gvwRFIs.Dock = System.Windows.Forms.DockStyle.Fill;
        this.gvwRFIs.Location = new System.Drawing.Point(3, 3);
        this.gvwRFIs.MultiSelect = false;
        this.gvwRFIs.Name = "gvwRFIs";
        this.gvwRFIs.ReadOnly = true;
        this.gvwRFIs.RowHeadersVisible = false;
        this.gvwRFIs.RowHeadersWidth = 4;
        this.gvwRFIs.SelectionMode = System.Windows.Forms.DataGridViewSelectionMode.FullRowSelect;
        this.gvwRFIs.Size = new System.Drawing.Size(1078, 422);
        this.gvwRFIs.TabIndex = 4;
        this.gvwRFIs.DoubleClick += new System.EventHandler(this.gvwRFIs_DoubleClick);

Consent Tab Control Designer Code

        // 
        // tabConsentInfoRFI
        // 
        this.tabConsentInfoRFI.Controls.Add(this.gvwRFIs);
        this.tabConsentInfoRFI.Controls.Add(this.lvwConsentInfoRFI);
        this.tabConsentInfoRFI.Location = new System.Drawing.Point(4, 32);
        this.tabConsentInfoRFI.Name = "tabConsentInfoRFI";
        this.tabConsentInfoRFI.Padding = new System.Windows.Forms.Padding(3);
        this.tabConsentInfoRFI.Size = new System.Drawing.Size(1084, 428);
        this.tabConsentInfoRFI.TabIndex = 4;
        this.tabConsentInfoRFI.Text = "RFI\'s";
        this.tabConsentInfoRFI.UseVisualStyleBackColor = true;

Processing Tab Control Designer Code

        // 
        // tabProcessingRFI
        // 
        this.tabProcessingRFI.Location = new System.Drawing.Point(4, 36);
        this.tabProcessingRFI.Name = "tabProcessingRFI";
        this.tabProcessingRFI.Padding = new System.Windows.Forms.Padding(3);
        this.tabProcessingRFI.Size = new System.Drawing.Size(868, 465);
        this.tabProcessingRFI.TabIndex = 1;
        this.tabProcessingRFI.Text = "RFI";
        this.tabProcessingRFI.UseVisualStyleBackColor = true;

Solution

  • I found the issue, The ListView that is in the consent designer code, is an old control that looks identical, but is no longer used. So when the control is parented back to the Origional tab, it is in the background of this control. Once the control was removed (thought it already was) the code worked perfectly.

    Thank you to LarsTech for getting me in the right direction. And akhisp for there answer.