在我的应用程序中,当我更改组合框中的适配器时,我得到了所有的网络适配器(如果我的机器有多个......) 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;
}
}