Hack Forums
[C#] delete item in Listbox and pc - Printable Version

+- Hack Forums (https://hackforums.net)
+-- Forum: Tech (https://hackforums.net/forumdisplay.php?fid=444)
+--- Forum: Coding (https://hackforums.net/forumdisplay.php?fid=151)
+---- Forum: Software Development (https://hackforums.net/forumdisplay.php?fid=118)
+---- Thread: [C#] delete item in Listbox and pc (/showthread.php?tid=5091972)



delete item in Listbox and pc - Natus12345 - Dec 12, 2015

How to delete items from ListBox .


* - Rhez - Dec 12, 2015

Delete Selected Item:
Code
ListBox1.Items.Remove(ListBox1.SelectedItem)

I don't get the "pc" problem there.


* - Natus12345 - Dec 13, 2015

(Dec 12, 2015 07:01 PM)Rhez Wrote:  Delete Selected Item:
Code
ListBox1.Items.Remove(ListBox1.SelectedItem)

I don't get the "pc" problem there.

this code only clear ListBox not delete text file in folder Example , sorry for english 😟
look this :
s15.postimg.org/ano0vny23/Screenshot_1.jpg

and this

s11.postimg.org/6qh3x6pr7/Screenshot_2.jpg


* - Odus - Dec 13, 2015

Sooo File.Delete from IO namespace? You need to take some initiative and search things for yourself.


* - Natus12345 - Dec 13, 2015

I search in internet and with File.Delete not working

foreach (var item in listBox1.SelectedItems)
{
File.Delete((string)item);
}


* - Odus - Dec 13, 2015

(Dec 13, 2015 06:09 AM)Natus12345 Wrote:  I search in internet and with File.Delete not working

Strong type your iterator and it'll handle the casting for you.

Code
foreach (string path in listBox1.SelectedItems)
    File.Delete(path);

Have you changed your ListBox control's SelectionMode property? It should be set to MultiSimple/Extended.


* - Natus12345 - Dec 13, 2015

(Dec 13, 2015 08:25 AM)Odus Wrote:  Strong type your iterator and it'll handle the casting for you.

Code
foreach (string path in listBox1.SelectedItems)
    File.Delete(path);

Have you changed your ListBox control's SelectionMode property? It should be set to MultiSimple/Extended.

look this :
s10.postimg.org/ou31a6ent/image.jpg

s10.postimg.org/btradqs3d/image.jpg


* - Odus - Dec 13, 2015

(Dec 13, 2015 10:22 AM)Natus12345 Wrote:  s10.postimg.org/btradqs3d/image.jpg

Read what it said. You still have it open in notepad or something.


* - Natus12345 - Dec 13, 2015

(Dec 13, 2015 10:40 AM)Odus Wrote:  Read what it said. You still have it open in notepad or something.

s29.postimg.org/825jhqsh3/Screenshot_1.jpg


* - He B TeMy - Dec 13, 2015

My god, don't post fucking prints, the error is self explanatory, you may not understand english, but i can't translate it more cause it's clearly self-explanatory!

The file is being used by another process.

Next time, copy the error code and details, not taking a fucking print which i need to zoom and guess some words.


* - Natus12345 - Dec 13, 2015

Topic can close my friend solve the error .