我如何...收集ComboBox的连接| VB.Net [英] How do I... Collect Connections to ComboBox | VB.Net

查看:80
本文介绍了我如何...收集ComboBox的连接| VB.Net的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  Dim  a = System.Net.NetworkInformation.NetworkInterface.GetAllNetworkInterfaces 
Dim b = a.Where( Function (x)x.NetworkInterfaceType = Net.NetworkInformation.NetworkInterfaceType.GenericModem)
对于 每个 i b
conList.Items .Add(i.Name)
下一页







http://prntscr.com/35c02l [ ^ ]

解决方案

首先,请参阅解决方案1作者:Sergey Alexandrovich Kryukov。



我建议阅读: NetworkInterface.GetAllNetworkInterfaces Method [ ^ ]。



我在下面的代码中测试过:

  Dim  adapters() As  NetworkInterface = NetworkInterface.GetAllNetworkInterfaces()

对于 每个适配器 As NetworkInterface 适配器中
' 取消注释下面的行只获取通用调制解调器
' 如果adapter.NetworkInterfaceType = Netw orkInterfaceType.GenericModem然后ListBox1.Items.Add(adapter.Name)
' 评论如下如果你只想列出通用调制解调器
ListBox1.Items.Add(adapter.Name)
Next


没有解释问题,所以这不是一个有效的问题。但是,我可以在代码中看到问题。将字符串存储在组合框或列表框中是个坏主意。你存储它们,查看它们,但代码将如何使用与项目相关的数据。



正确的想法在我过去的答案中解释:combobox.selectedvalue在winform中显示{} [ ^ ]。



也就是说,您不存储字符串,而是创建一些包含处理项目所需数据的类型。您可以随时执行此操作,因为该项可以是任何类型的对象。唯一的问题是控制项目在UI中的显示方式。简单地说:您只需覆盖 System.ToString()作为您的物品类型。



-SA

Dim a = System.Net.NetworkInformation.NetworkInterface.GetAllNetworkInterfaces
Dim b = a.Where(Function(x) x.NetworkInterfaceType = Net.NetworkInformation.NetworkInterfaceType.GenericModem)
For Each i In b
    conList.Items.Add(i.Name)
Next




http://prntscr.com/35c02l[^]

解决方案

First of all, please, see solution 1 by Sergey Alexandrovich Kryukov.

I'd suggest to read this: NetworkInterface.GetAllNetworkInterfaces Method[^].

I have tested below code:

Dim adapters() As NetworkInterface = NetworkInterface.GetAllNetworkInterfaces()

For Each adapter As NetworkInterface In adapters
    'uncomment below line to get only generic modems
    'If adapter.NetworkInterfaceType = NetworkInterfaceType.GenericModem Then ListBox1.Items.Add(adapter.Name)
    'comment below line if you want to list only generic modems
    ListBox1.Items.Add(adapter.Name)
Next


No problem is explained, so this is not a valid question. However, I can see a problem in the code. It's a bad idea to store just strings in a combo box or a list box. You store them, view them, but how the code will use the data associated with the items.

The correct idea is explained in my past answer: combobox.selectedvalue shows {} in winform[^].

That is, you store not the string, but create some type which contains data needed for your work with the items. You can always do it, because the item can be an object of any type. The only problem is to control how an item is shown in the UI. Simply: you just override System.ToString() for your item type.

—SA


这篇关于我如何...收集ComboBox的连接| VB.Net的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆