0

下面的代码最初只是根据名称从列表视图中删除了一个用户。我想添加首先将列表视图的标签属性写入文本文件的功能,但我对如何在删除它之前指定我想要标签的列表视图项目感到困惑。有人可以给我建议吗?谢谢。

Public Sub RemoveUser(ByVal name As Object)
    If _mainView.lvwChannelUsers.InvokeRequired Then
        _mainView.lvwChannelUsers.Invoke(New ParameterizedThreadStart(AddressOf RemoveUser), name)
    Else
        Dim lvi As ListViewItem = GetListViewItemsIndex(DirectCast(name, String))
        Dim FILE_NAME As String = Application.StartupPath & "\accounts\" & DirectCast(name, String)
        Dim objWriter As New System.IO.StreamWriter(FILE_NAME)
        objWriter.Write("This is where I need to call the tag to write.")
        objWriter.Close()
        _mainView.lvwChannelUsers.Items.Remove(lvi)
    End If
End Sub
4

1 回答 1

0

在这里,您有Sub执行所需操作的更正版本:

Public Sub RemoveUser(ByVal name As Object)
    If _mainView.lvwChannelUsers.InvokeRequired Then
        _mainView.lvwChannelUsers.Invoke(New ParameterizedThreadStart(AddressOf RemoveUser), name)
    Else
        Dim lvi As ListViewItem = _mainView.lvwChannelUsers.FindItemWithText(DirectCast(name, String))
        Dim FILE_NAME As String = Application.StartupPath & "\accounts\" & DirectCast(name, String)
        Dim objWriter As New System.IO.StreamWriter(FILE_NAME)
        objWriter.Write(lvi.Tag)
        objWriter.Close()
        _mainView.lvwChannelUsers.Items.Remove(lvi)
    End If
End Sub
于 2013-08-12T22:22:17.930 回答