Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. Copy selected listview item to a textbox VB.NET

Copy selected listview item to a textbox VB.NET

Scheduled Pinned Locked Moved Visual Basic
helpcsharpdatabasequestion
5 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P Offline
    P Offline
    Pete_123
    wrote on last edited by
    #1

    Hi, I'm working on a small project , I'm trying to copy a selected list view item to a textbox this will then use the text in the textbox to create a text file with the name as the textbox text. here is the code I have so far:

    If e.Button = Windows.Forms.MouseButtons.Left AndAlso e.Clicks = 1 Then
    For Each selectedItem In selectedItems
    REM ---lsvRQLiveFeed.Items.Remove(selectedItem)
    REM ---lstDJFeed.Items.Add(selectedItem)
    txtITEM.Text = lsvRQLiveFeed.SelectedItems(0).Text

                My.Computer.FileSystem.WriteAllText("C:\\Users\\Pete\\Desktop\\DJ Sync\\DJ Sync\\test\\REQUEST\\" + txtITEM.Text, +"." + ".txt", False)
    
            Next
    

    however I seem to get an error with the following line:

    txtITEM.Text = lsvRQLiveFeed.SelectedItems(0).Text

    InvalidArgument=Value of '0' is not valid for 'index'. Parameter name: index is there any solution I have been working for a while on this issue and I'm struggling to find a solution ? Any help with this greatly appreciated. Regards Pete

    L 1 Reply Last reply
    0
    • P Pete_123

      Hi, I'm working on a small project , I'm trying to copy a selected list view item to a textbox this will then use the text in the textbox to create a text file with the name as the textbox text. here is the code I have so far:

      If e.Button = Windows.Forms.MouseButtons.Left AndAlso e.Clicks = 1 Then
      For Each selectedItem In selectedItems
      REM ---lsvRQLiveFeed.Items.Remove(selectedItem)
      REM ---lstDJFeed.Items.Add(selectedItem)
      txtITEM.Text = lsvRQLiveFeed.SelectedItems(0).Text

                  My.Computer.FileSystem.WriteAllText("C:\\Users\\Pete\\Desktop\\DJ Sync\\DJ Sync\\test\\REQUEST\\" + txtITEM.Text, +"." + ".txt", False)
      
              Next
      

      however I seem to get an error with the following line:

      txtITEM.Text = lsvRQLiveFeed.SelectedItems(0).Text

      InvalidArgument=Value of '0' is not valid for 'index'. Parameter name: index is there any solution I have been working for a while on this issue and I'm struggling to find a solution ? Any help with this greatly appreciated. Regards Pete

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      txtITEM.Text = selectedItem.Text

      Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^]

      P 1 Reply Last reply
      0
      • L Lost User

        txtITEM.Text = selectedItem.Text

        Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^]

        P Offline
        P Offline
        Pete_123
        wrote on last edited by
        #3

        thank you that has fixed the issue only now i need to tackle the next error:

        Conversion from string "." to type 'Double' is not valid.

        on this line:

        My.Computer.FileSystem.WriteAllText("C:\Users\Pete\Desktop\DJ Sync\DJ Sync\test\REQUEST\" + txtITEM.Text, +"." + ".txt", False)

        any ideas ? Regards Pete

        L T 2 Replies Last reply
        0
        • P Pete_123

          thank you that has fixed the issue only now i need to tackle the next error:

          Conversion from string "." to type 'Double' is not valid.

          on this line:

          My.Computer.FileSystem.WriteAllText("C:\Users\Pete\Desktop\DJ Sync\DJ Sync\test\REQUEST\" + txtITEM.Text, +"." + ".txt", False)

          any ideas ? Regards Pete

          L Offline
          L Offline
          Lost User
          wrote on last edited by
          #4

          Yes, it's failing on the second parameter:

          , +"." + ".txt",

          It probably reads as 0 + ".". The second parameter is the stuff that is written to the file. If you omit the first + on that line, you'd be writing "..txt" to the file. You might want to divide the statement over multiple lines, makes it a bit easier;

          Dim sPath as String = String.Format("C:\Users\Pete\Desktop\DJ Sync\DJ Sync\test\REQUEST\{0}.txt", txtITEM.Text)
          Dim sContent as String = "Whatever your content is"
          My.Computer.FileSystem.WriteAllText(sPath, sContent, False)

          Bonus points can be earned by using the SpecialFolder enum to fetch the path to the desktop-directory, and Path.Combine to build the path.

          Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^]

          1 Reply Last reply
          0
          • P Pete_123

            thank you that has fixed the issue only now i need to tackle the next error:

            Conversion from string "." to type 'Double' is not valid.

            on this line:

            My.Computer.FileSystem.WriteAllText("C:\Users\Pete\Desktop\DJ Sync\DJ Sync\test\REQUEST\" + txtITEM.Text, +"." + ".txt", False)

            any ideas ? Regards Pete

            T Offline
            T Offline
            Tino Fourie
            wrote on last edited by
            #5

            txtITEM.Text, +"." + ".txt", False

            What's wrong there ? You can't have a "+" next to a ","

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups