我有一个 MdiParent 表格,我正在通过以下代码打开一个孩子:
private void editCategoryToolStripMenuItem_Click(object sender, EventArgs e)
{
formHide();
EditCatagoryGrid objEditCategoryGrid = new EditCatagoryGrid();
objEditCategoryGrid.MdiParent = this;
objEditCategoryGrid.Location = new Point(100, 80);
objEditCategoryGrid.Show();
}
public void formHide()
{
Form[] form = this.MdiChildren;
foreach (Form f in form)
{
f.Hide();
//ChangeMdiColor();
}
}
中有一个datagridview
礼物EditCatagoryGrid
。当我在EditCatagoryGrid
不使用 mdiform 的情况下打开表单时,它工作正常,但是当使用 mdiparent 表单时,更改中存在的 datagridview 的列索引EditCatagoryGrid
,它不起作用。我一直无法弄清楚这个问题。有人可以帮忙吗?
@Desolate 感谢您的回复,我绑定datagridview的代码如下:
private void EditCatagoryGrid_Load(object sender, EventArgs e)
{
bindDataGridView();
addCategoryComboBoxToDataGridView();
//closeAllOtherForms();
}
public void bindDataGridView()
{
objCon = new SqlCeConnection(@"Data Source= E:\Showroom software\Showroom software\SalePurchase.sdf ;Persist Security Info=False;");
objCon.Open();
objDa = new SqlCeDataAdapter("select CategoryId from Category", objCon);
DataTable dt = new DataTable();
objDa.Fill(dt);
dataGridView1.DataSource = dt;
objCon.Close();
}
public void addCategoryComboBoxToDataGridView()
{
dataGridView1.Columns.Add(Category);
Category.Name = "cmbcatagory";
Category.HeaderText = "Category";
Category.Width = 150;
dataGridView1.Columns[1].Width = 100;
dataGridView1.AllowUserToAddRows = false;
}