c# combobox用法

.Net技术 码拜 9年前 (2016-03-05) 1063次浏览
这样添加了还是显示不了怎么解决阿?

 private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            for (int c = 0; c < app.ComponentCount; c++)
            {
                IvcComponent comp = app.getComponent(c);
                for (int i = 0; i < comp.PropertyCount; i++)
                {
                    string propName = comp.getPropertyName(i);
                    object propValue = comp.getProperty(propName);
                    comboBox1.Items.Add(propName + "::" + propValue);
                }
                
            }
        }
解决方案

40

这样写
List items = new List<string>();
for (int c = 0; c < app.ComponentCount; c++)
{
IvcComponent comp = app.getComponent(c);
for (int i = 0; i < comp.PropertyCount; i++)
{
string propName = comp.getPropertyName(i);
object propValue = comp.getProperty(propName);
items.Add(propName + “::” + propValue);
}
comboBox1.ItemResource = items;
}

CodeBye 版权所有丨如未注明 , 均为原创丨本网站采用BY-NC-SA协议进行授权 , 转载请注明c# combobox用法
喜欢 (0)
[1034331897@qq.com]
分享 (0)