none
VS 2010 ListView 物件問題 RRS feed

  • 問題

  •  Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
      Dim RC As String
      Dim item As New ListViewItem()
      RC = File.ReadAllText("C:\Reg Record\RegRecordAction.txt")
      item.SubItems.Add(RC)
      ListView1.Items.Add(item)
     End Sub
    

    Q1 : 如何指定你要的標籤來顯示你想要的東西?

    Q2 : 字串問題 如下圖  如何把某標籤的某段字串 剪下 移動另一個標籤

     

    • 已移動 璉璉 2011年1月29日 上午 01:25 (從:Visual Studio一般討論區(General))
    2011年1月24日 上午 03:02

解答

  • Q1. 要指定什麼標籤,資料來源是什麼? 是否能詳述問題?

          參考 MSDN 範例http://msdn.microsoft.com/zh-tw/library/system.windows.forms.listviewitem(v=vs.80).aspx

    Q2. ReadAllText 後,做 String.Split


    歡迎參觀我的Blog.NET菜鳥自救會
    • 已標示為解答 Just Lin 2011年1月24日 上午 11:53
    2011年1月24日 上午 06:21
  • OK, we have to do the following,

    1) Use File.ReadAllLines rather than ReadAllText
    2) Use String.Split to split each lines into 2 part, first part is date, second part is your message, it may be AddReg/CreateReg/DeleteReg
    3) because the separator is not included in the first part of the string, which we need it, so add the "日" back to the strDate
    4) Create ListViewItem and add them to ListView

      Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim Path As String = "C:\Reg Record\RegRecordAction.txt"
        Dim readText() As String = File.ReadAllLines(Path)
        Dim s As String
        Dim item As ListViewItem
        Dim strSplit As String()
        Dim strDate, strMessage As String
        For Each s In readText
          strSplit = s.Split({"日"c}, StringSplitOptions.None)
          strDate = strSplit(0) + "日"
          strMessage = strSplit(1)
          item = New ListViewItem(strDate)
          item.SubItems.Add(strMessage)
        Next
      End Sub
    

    大家一齊探討、學習和研究,謝謝!
    Microsoft MVP, Microsoft Community Star(TW & HK), MCT,
    MCSD, MCAD, MCSE+I, MCDBA, MCDST, MCSA, MCTS, MCITP, MCPD
    • 已標示為解答 Just Lin 2011年1月24日 上午 11:48
    2011年1月24日 上午 08:23

所有回覆

  • Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
      Dim RC As String
      Dim item As New ListViewItem(DateTime.Now.ToString())

      RC = File.ReadAllText("C:\Reg Record\RegRecordAction.txt")
      item.SubItems.Add(RC)
      ListView1.Items.Add(item)
    End Sub


    大家一齊探討、學習和研究,謝謝!
    Microsoft MVP, Microsoft Community Star(TW & HK), MCT,
    MCSD, MCAD, MCSE+I, MCDBA, MCDST, MCSA, MCTS, MCITP, MCPD
    2011年1月24日 上午 06:19
  • Q1. 要指定什麼標籤,資料來源是什麼? 是否能詳述問題?

          參考 MSDN 範例http://msdn.microsoft.com/zh-tw/library/system.windows.forms.listviewitem(v=vs.80).aspx

    Q2. ReadAllText 後,做 String.Split


    歡迎參觀我的Blog.NET菜鳥自救會
    • 已標示為解答 Just Lin 2011年1月24日 上午 11:53
    2011年1月24日 上午 06:21
  • 抱歉 沒有給你看夠多程式碼

     Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
      On Error Resume Next
      Dim WshShell
      If Dir("C:\Reg Record") = "" Then
       System.IO.Directory.CreateDirectory("C:\Reg Record")
      End If
      Dim g As String = TextBox2.Text
      WshShell = CreateObject("WScript.Shell")
      WshShell.RegDelete("" & g)
      Dim AllStr As String
      AllStr = Now.Year.ToString & " 年 " & Now.Month.ToString & " 月 " & Now.Day & " 日 " & " DeleteReg " & TextBox2.Text
      If Dir("C:\Reg Record\RegRecordAction.txt") = "" Then
       File.Create("C:\Reg Record\RegRecordAction.txt")
      End If
      File.AppendAllText("C:\Reg Record\RegRecordAction.txt", Environment.NewLine + AllStr)
     End Sub
    
     Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
      Dim RC As String
      Dim item As New ListViewItem()
      RC = File.ReadAllText("C:\Reg Record\RegRecordAction.txt")
      item.SubItems.Add(RC)
      ListView1.Items.Add(item)
     End Sub
    
    2011年1月24日 上午 07:43
  • OK, we have to do the following,

    1) Use File.ReadAllLines rather than ReadAllText
    2) Use String.Split to split each lines into 2 part, first part is date, second part is your message, it may be AddReg/CreateReg/DeleteReg
    3) because the separator is not included in the first part of the string, which we need it, so add the "日" back to the strDate
    4) Create ListViewItem and add them to ListView

      Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim Path As String = "C:\Reg Record\RegRecordAction.txt"
        Dim readText() As String = File.ReadAllLines(Path)
        Dim s As String
        Dim item As ListViewItem
        Dim strSplit As String()
        Dim strDate, strMessage As String
        For Each s In readText
          strSplit = s.Split({"日"c}, StringSplitOptions.None)
          strDate = strSplit(0) + "日"
          strMessage = strSplit(1)
          item = New ListViewItem(strDate)
          item.SubItems.Add(strMessage)
        Next
      End Sub
    

    大家一齊探討、學習和研究,謝謝!
    Microsoft MVP, Microsoft Community Star(TW & HK), MCT,
    MCSD, MCAD, MCSE+I, MCDBA, MCDST, MCSA, MCTS, MCITP, MCPD
    • 已標示為解答 Just Lin 2011年1月24日 上午 11:48
    2011年1月24日 上午 08:23