Copy selected listview item to a textbox VB.NET
-
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).TextMy.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
-
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).TextMy.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
-
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
-
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
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[^]
-
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
txtITEM.Text, +"." + ".txt", False
What's wrong there ? You can't have a "+" next to a ","