|
-
Jul 25th, 2008, 11:55 AM
#1
Thread Starter
Addicted Member
Rename A Listbox's Selected Item
Hi, how do I set the name of a listbox's selected item to a name of choice?
Any help is greatly appreciated,
Louix
-
Jul 25th, 2008, 12:36 PM
#2
Re: Rename A Listbox's Selected Item
remove it
vb Code:
listbox1.items.removeat(index)
, then insert modified item
vb Code:
listbox1.items.insert(index)
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Jul 25th, 2008, 12:56 PM
#3
Re: Rename A Listbox's Selected Item
Does your listbox, by any chance, contain the names of physical disk files that you need to rename?
-
Jul 25th, 2008, 01:01 PM
#4
Thread Starter
Addicted Member
Re: Rename A Listbox's Selected Item
Hack: It does actually
-
Jul 25th, 2008, 01:04 PM
#5
Re: Rename A Listbox's Selected Item
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?
-
Jul 25th, 2008, 01:07 PM
#6
Thread Starter
Addicted Member
Re: Rename A Listbox's Selected Item
Last edited by Louix; Jul 25th, 2008 at 01:12 PM.
-
Jul 25th, 2008, 01:36 PM
#7
Re: Rename A Listbox's Selected Item
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
-
Jul 25th, 2008, 05:34 PM
#8
Thread Starter
Addicted Member
Re: Rename A Listbox's Selected Item
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.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|