[英]I have a DataGridView on my form that is not being displayed when I run my form. Why?
我在名為panel10的面板上有一個名為StatGrid的DataGridView。 當我運行程序時,我使用以下代碼填充並獲取該DataGridView:
PubVars.active = true;
lblPanelTitle.Text = "Folder Status";
using (SqlConnection connect = new SqlConnection(PubVars.connStr))
{
string query = "SELECT viewfldr, status FROM Folders WHERE username = '" + PubVars.usrName + "'";
DataTable dt = new DataTable();
using (SqlDataAdapter da = new SqlDataAdapter(query, connect))
{
connect.Open();
da.Fill(dt);
connect.Close();
}
DataGridViewCellStyle style = new DataGridViewCellStyle();
style.Font = new Font(this.Font, FontStyle.Bold);
try
{
statGrid.DataSource = dt;
statGrid.Columns[0].HeaderCell.Style = style;
statGrid.Columns[1].HeaderCell.Style = style;
statGrid.ColumnHeadersDefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter;
statGrid.Columns[0].Width = 400;
}
catch(Exception ex)
{
MessageBox.Show(ex.Message.ToString());
return;
}
}
panel1.Visible = false;
panel2.Visible = false;
panel3.Visible = false;
panel4.Visible = false;
panel5.Visible = false;
panel6.Visible = false;
panel7.Visible = false;
panel8.Visible = false;
panel9.Visible = false;
panel10.Visible = true;
statGrid.Focus();
當我運行窗體和代碼到達面板時,但未顯示DataGridView。 有人可以告訴我為什么會這樣嗎?
謝謝。
我認為您錯過了調用Bind()方法的嘗試,請嘗試使用此statGrid.Bind()
我找到了答案。 panel10的父母不是表格。 是panel9。 當我將panel10直接移到“文檔大綱”選項卡中的表單下方時,便對其進行了修復。 謝謝大家的幫助。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.