请教各位高手。我在利用反射方法给combobox控件赋值时候总是失败,是啥回事? 是不是不能使用
自定义的ilist对象作为combobox控件的数据源?换是DataTable对象时是可以的。请大家帮我看看。
代码如下:
public class clsListItem
{
    private string myName;
    private string myValue;    public string ItemValue
    {
        get
        {
            return myValue;
        }        set
        {
            this.myValue = value;
        }
    }    public string ItemName
    {
        get
        {
            return myName;
        }        set
        {
            this.myName = value;
        }    }    public override string ToString()
    {
        return myName.ToString();
    }
}using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Collections;
using System.Windows.Forms;
using System.Reflection;
namespace tttt
{
public class
{
void test()
{
IList dtSource = new ArrayList();clsListItem item;
item = new clsListItem();
item.ItemName = "1";
item.ItemValue="1";
dtSource.Add(item);item = new clsListItem()
item.ItemName = "2";
item.ItemValue="2";
dtSource.Add(item);control.DataSource = dtSource;//control是一个combobox对象
control.DisplayMember = "ItemName";
control.ValueMember = "ItemValue";
Type controlType = control.GetType();
PropertyInfo controlProperty =controlType.GetProperty("SelectedValue", typeof(object));
controlProperty.SetValue(control, 1,  null);
}
}
}