使用Telerik radDropDownList

时间:2014-03-27 17:08:19

标签: c# .net winforms telerik

我有Winforms个应用程序,我想使用Telerik个控制器而不是Winforms个控制器。

我的应用程序Combobox可以获取我的所有计算机Network adapters

private NetworkAdapter selectedAdapter = null;
ComboBox comboBoxAdapter;

我的机器适配器是NetworkAdapter的类型。 在我的应用程序启动后,我得到所有适配器:

IEnumerable<NetworkAdapter> res = NetworkAdapter.getAll();

将所有适配器插入我的Combobox

 this.ActiveControl = comboBoxAdapter;
 comboBoxAdapter.Items.AddRange(res.ToArray());

comboBoxAdapter_SelectedIndexChanged

private void comboBoxAdapter_SelectedIndexChanged(object sender, EventArgs e)
{
    ComboBox cmb = sender as ComboBox;
    selectedAdapter = cmb.SelectedItem as NetworkAdapter;
}

现在我添加Telerik radDropDownList 由于Telerik radDropDownList AddRange仅收到string,我将NetworkAdapter放在List<string>内:

List<string> addList = new List<string>();

foreach (NetworkAdapter add in NetworkAdapter.getAll())
    addList.Add(add.Description);

radDropDownList1.Items.AddRange(addList);

我有这个问题:

这是我的radDropDownList1_SelectedIndexChanged

private void radDropDownList1_SelectedIndexChanged(object sender, Telerik.WinControls.UI.Data.PositionChangedEventArgs e)
{
    ComboBox cmb = sender as ComboBox;
    selectedAdapter = cmb.SelectedItem as NetworkAdapter;
}

出于某种原因,selectedAdapter始终是null

1 个答案:

答案 0 :(得分:0)

只是想知道为什么你仍然使用ComboBox来投射发送者(在你最后的menthod上)

private void radDropDownList1_SelectedIndexChanged(object sender, Telerik.WinControls.UI.Data.PositionChangedEventArgs e)
{
    ComboBox cmb = sender as ComboBox;
    selectedAdapter = cmb.SelectedItem as NetworkAdapter;
}

我认为应该是

private void radDropDownList1_SelectedIndexChanged(object sender, Telerik.WinControls.UI.Data.PositionChangedEventArgs e)
{
    var cmb = sender as RadDropDownList;
    selectedAdapter = cmb.SelectedItem as NetworkAdapter;
}

虽然我不确定。