I am pragmatically creating TabPage with DataGridView. The TabPage's are appearing correctly, but they are missing the DataGridView. Anyone able to discern why they DGV's are not appearing with the tabs? The LoadDataGridToTab is in the correct form. It is being called from another Form though. Should?
public void LoadDataGridToTab(Main main, string category)
{
try
{
//Set Cell Style
var dataGridViewCellStyle = new DataGridViewCellStyle
{
Alignment = DataGridViewContentAlignment.MiddleLeft,
BackColor = SystemColors.Control,
Font = new Font("Microsoft Sans Serif", 8.25F,
FontStyle.Regular, GraphicsUnit.Point, 0),
ForeColor = SystemColors.WindowText,
SelectionBackColor = SystemColors.Highlight,
SelectionForeColor = SystemColors.HighlightText,
WrapMode = DataGridViewTriState.True
};
//Make the Grid
var grid = new DataGridView
{
Name = "dgv_" + category,
Text = category,
Visible = true,
Dock = DockStyle.Fill,
AllowUserToAddRows = false,
AllowUserToDeleteRows = false,
AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill,
ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize,
ColumnHeadersDefaultCellStyle = dataGridViewCellStyle,
DataSource = Auction.CacheAuctionsDataSet.Tables[category]
};
//Binding
//var source = new BindingSource();
//source.DataSource = CacheAuctionsDataSet.Tables[category];
//Made the Tab
var tmpTabPage = new TabPage(category)
{
Name = "tabctrl_" + category,
Text = category,
Visible = true
};
//Add the Grid to the Tab
tmpTabPage.Controls.Add(grid);
tmpTabPage.Refresh();
//Add the Tab to the Control
tabctrl_Auctions.Controls.Add(tmpTabPage);
tabctrl_Auctions.Refresh();
}
catch (Exception ex)
{
Console.WriteLine(ex.ToString());
}
}