VB 如何将listview自动写入文本框
展开全部
Private Sub lv2txt(LV As ListView, txt As TextBox)
txt.text = ""
'将listview的列头写入Text控件中
For i = 1 To LV.ColumnHeaders.Count
If txt.text = "" Then
txt.text = LV.ColumnHeaders(i).text
Else
txt.text = txt.text & vbTab & LV.ColumnHeaders(i).text
End If
Next
'将listview中的listitem逐行写入Text控件中
For i = 1 To LV.ListItems.Count
txt.text = txt.text & vbCrLf & LV.ListItems(i).text
For j = 2 To LV.ColumnHeaders.Count
txt.text = txt.text & vbTab & LV.ListItems(i).SubItems(j - 1)
Next j
Next
End Sub
Private Sub Command1_Click()
'假设你的listview控件名称为ListView1,Text控件名称为Text1
'请在设计时并将Text1的MultiLine属性设置为True
Call lv2txt(ListView1, Text1)
End Sub
txt.text = ""
'将listview的列头写入Text控件中
For i = 1 To LV.ColumnHeaders.Count
If txt.text = "" Then
txt.text = LV.ColumnHeaders(i).text
Else
txt.text = txt.text & vbTab & LV.ColumnHeaders(i).text
End If
Next
'将listview中的listitem逐行写入Text控件中
For i = 1 To LV.ListItems.Count
txt.text = txt.text & vbCrLf & LV.ListItems(i).text
For j = 2 To LV.ColumnHeaders.Count
txt.text = txt.text & vbTab & LV.ListItems(i).SubItems(j - 1)
Next j
Next
End Sub
Private Sub Command1_Click()
'假设你的listview控件名称为ListView1,Text控件名称为Text1
'请在设计时并将Text1的MultiLine属性设置为True
Call lv2txt(ListView1, Text1)
End Sub
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询