如何从组合框vb中获取数据 [英] How to get data from a combo-box vb
本文介绍了如何从组合框vb中获取数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试图从vb中的组合框中获取所有的数据。假设值是john,sarah,bob。我想要能够把这些写入到这样的文本文件中:
I am trying to get all the data from a combo-box in vb. Lets say the values are john, sarah, bob. I want to be able to write those to a text file like this:
John
Sarah
Bob
John Sarah Bob
他们是使用
combobox.add.item(sarah)
有没有我可以做这样的事吗?
Is there anyway I can do somthing like this?
names = combobox.list.items
推荐答案
在c#中会是这样的
string names = string.Join(", ", comboBox.Items.Cast<object>()
.Select(i => i.ToString()));
以下是与vb.net相同的片段(自动)
Here's the same snippet (auto)translated to vb.net
Dim names As String = String.Join(", ", comboBox.Items.Cast(Of Object)().Select(Function(i) i.ToString()))
或者你可以通过一个简单的循环遍历所有的项目并使用一个stringbuilder,项目。
Or you can do a simple loop through all the items and use a stringbuilder and concatenate each item.
Dim sb As New StringBuilder()
For Each item As Object In comboBox.Items
sb.AppendFormat("{0}, ", item)
Next
Dim names As String = sb.ToString()
这篇关于如何从组合框vb中获取数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文