gpt4 book ai didi

c# - 将数据从父级传递到对话框

转载 作者:行者123 更新时间:2023-11-30 14:03:47 25 4
gpt4 key购买 nike

我有一个对话框形式的组合框。我需要用父表单中的 List<> 填充此组合。我无法通过对话框构造函数传递 List<>,该怎么做。

frmChild frm = new frmChild();
frm.ShowDialog();

最佳答案

您可以在您的表单上添加一个属性或方法,它采用 List<items>并填充组合框。

例如:

List<ItemType> items = GetItemsForFormsComboBox();
frmChild frm = new frmChild();
frm.SetComboItems(items);
frm.ShowDialog();

// in the form
public void SetComboItems(List<ItemType> items)
{
foreach(var item in items)
{
myCombo.Add( /* construct combo item and use item to populate it here */ );
}
}

关于c# - 将数据从父级传递到对话框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3477152/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com