c#DataGridview Combobox Comlumn未显示所选值 [英] c# DataGridview Combobox Comlumn not displaying selected value
问题描述
我正在使用普通的Datagridview,但我遇到了问题。
这样我在网格中填充数据并向其中添加了combobox列
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]。值= dgr。单元格[ PermittedUserId]。值;
}
我在MDI父母面前打开此表格
< pre lang =c#> Form1 frm = new Form1(){MdiParent = MdiForm1};
frm.Show();
当我打开表单时它没有在Comboboxcolumn中显示任何选定的值
但是当我打开我的Form frm1而不是它MdiParent它在Combobox列中显示选定的值
Form1 frm = new Form1( );
frm.Show();
所以这真的发生了,因为它在我没有MdiParnet显示我的表单时显示数据,或者是否有任何其他原因因为它没有发生< br>
请给我更好的建议..因为显示没有MdiParent的形式是无效的解决方案。
我遇到了同样的问题。我相信你正在填写表格Load事件上的DGV。如果您将该代码移动到Form Activivate,那么这应该在MDI表单中
I am using a normal Datagridview but I have a problem with it.
This way I am filling data in my grid and adding combobox column to it
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;
}
I am opening this Form in a MDI parent
Form1 frm = new Form1() { MdiParent = MdiForm1};
frm.Show();
when I open my form it not displaying any selected value in Comboboxcolumn
But when I open my Form frm1 not it MdiParent it display selected value in Comboboxcolumn
Form1 frm = new Form1();
frm.Show();
so is this really happen because it shows data when i am showing my form without MdiParnet or is there any other reason due to which it is not happening<br>
Please give me better suggesstion.. because showing form without MdiParent is not valid solution.
I had the same problem. I believe you are populating the DGV on form Load event. If you move that code to Form Activivate then this should work within MDI form
这篇关于c#DataGridview Combobox Comlumn未显示所选值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!