Hi, how do I set the name of a listbox's selected item to a name of choice?
Any help is greatly appreciated,
Louix :)
Printable View
Hi, how do I set the name of a listbox's selected item to a name of choice?
Any help is greatly appreciated,
Louix :)
remove it, then insert modified itemvb Code:
listbox1.items.removeat(index)vb Code:
listbox1.items.insert(index)
Does your listbox, by any chance, contain the names of physical disk files that you need to rename?
Hack: It does actually :)
Then you would want to use My.Computer.FileSystem.RenameFile
The source file would the be selected item from your listbox.
How will the new file name get fed in?
Do you have textbox or something like that?
Yes, through a textbox.
Then try something like this. Bear in mind, that you listbox items and your textbox would both have to have the complete path and filename displayed in order for this to work. If that is not the case, then the rename would need to be modified in order to append the path to the file name.Code:Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim i As Integer
For i = 0 To ListBox1.Items.Count - 1
If ListBox1.GetSelected(i) = True Then
My.Computer.FileSystem.RenameFile(ListBox1.Text, TextBox1.Text)
Exit For
End If
Next
End Sub
I have code that renames the file (in a special way I need it to), but I need code that renames the listbox's selected item so everything matches up.
I don't get back to my dev machine until tomorrow, but the code you posted doesn't change the selected items text (?).
Thank you for taking the time to reply but is there a way to make the text change? If you need it, I'll show you what I mean by my "special way" tomorrow.
Louix.