如何从文本框中将项目插入listview控件 [英] How do I insert items into a listview control from textbox
本文介绍了如何从文本框中将项目插入listview控件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个包含两列的列表视图。我也有一个文本框。在文本框中,有一些带有字符串的行我想插入到列表视图中。
每一行都将插入第一列,每一行将插入第二列。我将如何实现这一点。
这是我目前的代码:
私人 Sub Form1_Load( ByVal sender 作为系统。对象, ByVal e 作为系统。 EventArgs)句柄 MyBase .Load
TextBox3.Text = My.Resources.clsid
Dim ListArr( 230 ) As < span class =code-keyword> String
Dim i As < span class =code-keyword>整数 = 0
对于 < span class =code-keyword>每个行作为 字符串 在 TextBox3.Lines
ListArr(i)= line(i)
i + = 1
对于 每个 litem 作为 字符串 在 ListArr
AddLitem(litem,litem)
下一步
下一步
结束 Sub
公共 功能 AddLitem( ByVal Desc 正如 字符串, ByVal CLSID As 字符串)
Dim litem As ListViewItem
如果 i = 0 那么
Lstr ( 0 )= Desc
i + = 1
ElseIf i = 1 然后
Lstr( 1 )= Desc
litem = 新 ListViewItem(Lstr)
ListView1.Items.Add( litem)
ListView1.Items.RemoveAt(ListView1.Items.Count)
结束 如果
Lstr( 0 )= Desc
' Lstr(1)= CLSID
结束 功能
请帮帮我。
提前谢谢。
解决方案
我不明白你的问题,但如果你只想添加值为ListView
列。请参考下面的代码:
此代码只是从文本框中读取行并添加到ListView
列。
< pre lang =vb> Dim mTextBoxLines As String ()= 我 .TextBox1.Lines ' 从TextBox读取行
Dim mLine 作为 Int16 = 1
' 将第一行添加到ListView的第一列
Dim mListViewItem As ListViewItem = 新 ListViewItem(mTextBoxLines( 0 ))
while mLine<> mTextBoxLines.Count
' 将其他行添加到ListView的下一列
mListViewItem .SubItems.Add(mTextBoxLines(mLine))
mLine = mLine + 1
结束 while
Me .ListView1.Items.Add(mListViewItem)
我希望它会对你有所帮助。 :)
I have a listview with two columns. I also have a textbox. In the textbox, there are lines with strings that I want to insert into the listview.
Every 1st line will be inserted into the first column and every 2nd line will be inserted into the second column. How would I achieve this.
This is my current code:
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
TextBox3.Text = My.Resources.clsid
Dim ListArr(230) As String
Dim i As Integer = 0
For Each line As String In TextBox3.Lines
ListArr(i) = line(i)
i += 1
For Each litem As String In ListArr
AddLitem(litem, litem)
Next
Next
End Sub
Public Function AddLitem(ByVal Desc As String, ByVal CLSID As String)
Dim litem As ListViewItem
If i = 0 Then
Lstr(0) = Desc
i += 1
ElseIf i = 1 Then
Lstr(1) = Desc
litem = New ListViewItem(Lstr)
ListView1.Items.Add(litem)
ListView1.Items.RemoveAt(ListView1.Items.Count)
End If
Lstr(0) = Desc
'Lstr(1) = CLSID
End Function
Please help me.
Thanks in advance.
解决方案
Hi, i did not understand your question, but if you simply want to add values in to theListView
columns. Please refer below code:
This code simply read lines from text box and add into theListView
columns.
Dim mTextBoxLines As String() = Me.TextBox1.Lines 'Read Lines From TextBox Dim mLine As Int16 = 1 'Add First Line Into the First Column Of ListView Dim mListViewItem As ListViewItem = New ListViewItem(mTextBoxLines(0)) While mLine <> mTextBoxLines.Count 'Add Other Lines Into the Next Columns Of ListView mListViewItem.SubItems.Add(mTextBoxLines(mLine)) mLine = mLine + 1 End While Me.ListView1.Items.Add(mListViewItem)
I hope it will help you. :)
这篇关于如何从文本框中将项目插入listview控件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文