组合框索引更改后更新标签

时间:2012-12-09 16:02:13

标签: c# winforms

在我的应用程序中我得到了所有的网络适配器 当我更改我的组合框内的适配器(以防我的机器有多个......) combo-box_SelectedIndexChanged函数调用我的函数并收到了适配器,我的问题是在组合框索引改变后我的函数没有更新我的标签。

在这一行:IEnumerable<NetworkAdapter> add = adapter.getAdapterInfo();我收到了我的适配器集合,每个适配器都有自己的属性(名称,ID,速度,IP ......)

private void comboBoxAdaptersWindow_SelectedIndexChanged(object sender, EventArgs e)
{
    ComboBox combobox = sender as ComboBox;
    NetworkAdapter selectedNic = combobox.SelectedItem as NetworkAdapter;
    UpdateForm(selectedNic);
}


private void UpdateForm(NetworkAdapter adapter)
{
    IEnumerable<NetworkAdapter> add = adapter.getAdapterInfo();
    List<NetworkAdapter> adaptersList = add.ToList();

    for (int i = 0; i < adaptersList.Count; i++) //update my labels
    {
        lblName2.Text = adaptersList[i]._name;
        lblId2.Text = adaptersList[i]._id;
        lblInterfaceType2.Text = adaptersList[i]._networkInterfaceType;
        lblIPv4Address2.Text = adaptersList[i]._ipAddress;
        lblDefaultGateway2.Text = adaptersList[i]._gatewayIpAddress;
        lblMacAddress2.Text = adaptersList[i]._macAddress;
        lblSpeed2.Text = adaptersList[i]._speed;
    }
}

0 个答案:

没有答案