2013-11-23 213 views
1

我使用的是正常的DataGridView但我有一个问题的。
这样我填写我的网格数据和添加组合框列到它DataGridView的组合框柱不显示选择组合框的值

db.DataEntities ss = new db.DataEntities(); 
DataGridview1.DataSource = ss.table1.ToList(); 

if (!DataGridview1.Columns.Contains("dgcolUser")) 
{ 
    DataGridViewComboBoxColumn dgcombocolUser = new DataGridViewComboBoxColumn(); 
    dgcombocolUser.Name = "dgcolUser"; 

    var listOfAllUsers = ss.secAccountInformations.ToList(); 
    dgcombocolUser.DataSource = listOfAllUsers; 
    dgcombocolUser.DisplayMember = "AccountName"; 
    dgcombocolUser.ValueMember = "UserId"; 
    DataGridview1.Columns.Add(dgcombocolUser); 
} 

foreach (DataGridViewRow dgr in DataGridview1.Rows) 
{ 
    dgr.Cells["dgcolUser"].Value = dgr.Cells["PermittedUserId"].Value; 
} 

我在MDI父打开这个表

Form1 frm = new Form1() { MdiParent = MdiForm1}; 
frm.Show(); 

当我打开我的形式,它不显示任何Comboboxcolumn中选定的值 但是当我打开我的窗体frm1不是它MdiParent它显示在Comboboxcolumn中的选定值

Form1 frm = new Form1(); 
frm.Show(); 

所以这真的发生,因为它显示了当我显示我的表格数据,而无需MdiParnet或者是有由于它是不会发生
请给我更好的宝贵意见任何其他原因..因为显示了不的MdiParent形式不是有效的解决方案。

+0

无法重现内工作;这听起来也不合逻辑。观察这两种不同行为的最可能原因是,在其中一个行为中,foreach循环没有达到(之前发生崩溃)。调试代码并确认是这种情况。如果仍然看不到这个问题提供更清晰的信息:编写整个代码(如果有更多的在您发布的3段之间),确认您的意思是frm.Controls.Add(DataGridView中)等 – varocarbas

+0

@varocarbas感谢评论......但在3个片段之间并没有发生任何事情,也没有发生崩溃事件..虽然如果有任何崩溃比它也没有给出正确的输出,同时显示它没有Mdi父母 –

+0

好。注意,如果一个“轻碰撞”发生(例如,在做dgr.Cells [“dgcolUser”]。值=“thisVal”何时“thisVal”不是组合框的一个元素),无线的代码将被分析之后,但之前的所有代码都将被完美地解释(=正是你所抱怨的以及我无法再现的内容)。请调试代码并确认循环已完成(并且它遍历所有单元格没有任何问题)。 – varocarbas

回答

0

我有同样的问题。我相信你正在填充Load事件中的DGV。如果移动代码形式被活化事件那么这应该MDI形式