【问题标题】:How to load data into listbox from text box?如何从文本框中将数据加载到列表框中?
【发布时间】:2012-05-07 13:26:04
【问题描述】:

您好,我需要一点帮助。

我的部分问题:

  • 首先,读取一个文本文件。
  • 将文本文件中的项目添加到 TextBox 和 ListBox 中。

我的文本文件中的示例数据是这样的:

A;猫;狗;老鼠;鸟

在哪里,“;”是分隔符,数据只是一行。
“A”必须加载到 TextBox 中,“Cat,.....,Bird”必须加载到 ListBox 中,每只动物一行。 我已经阅读了文本文件并将“A”加载到文本框中。
但不知道如何将其余数据加载到列表框中。

任何帮助都会很棒。

【问题讨论】:

  • 家庭作业?您尝试加载其余数据是什么?

标签: vb.net listbox fileopendialog


【解决方案1】:

这真的很简单,您应该查看MSDN page 以了解有关 ListBox 和其他相关内容的更多信息。

Dim str As String = "A;Cat;Dog;Rat;Bird"  'should have read from your text file

Dim arr As String() = str.Split(New Char() {";"})
Dim i As Integer
For i = 1 To arr.Length - 1
     ListBox1.Items.Add(arr(i))
Next i

【讨论】:

    【解决方案2】:
    string[] strArrr = "A;Cat;Dog;Rat;Bird".Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries);
            for (int i = 1;i< strArrr.Length - 1; i++)
            {
               listbox.items.add(strarrr[i]);
            }
    

    【讨论】:

      猜你喜欢
      • 2015-06-25
      • 1970-01-01
      • 1970-01-01
      • 2015-06-06
      • 2012-03-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多