Question Listbox Remove element

k0081

Member
Joined
Aug 25, 2021
Messages
18
Programming Experience
1-3
Hello to everyone

How can I delete the elements in listbox1 with a double click?
 
Please post in the most appropriate forum for the subject of the question. You have asked how to do something with a ListBox but you've posted in the C# General forum, so we have no idea what ListBox control you're talking about. If you had posted in the correct forum then we'd know without your having to state it explicitly. I'm guessing Windows Forms but if I answer and I've guessed wrongly then I've wasted my time and yours. Please specify the technology in use so that we can move this thread and provide appropriate advice.

BTW, this is a dedicated C# site so you don't have to specify C# in the thread title.
 
Also, please be more specific in your explanation of the problem. Do you mean that you want to delete the item that you double-clicked on? If so then you should say that, rather than "delete the elements", which could easily be interpreted as deleting every item. Just provide a FULL and CLEAR explanation of the problem, rather than trying to be as brief as possible.
 
Assuming that you want to delete the item you double-clicked on, you can handle the MouseDoubleClick event, call the IndexFromPoint method of the control to get the item index and then call Items.RemoveAt. Keep in mind that it is possible to double-click on an area that doesn't contain an item.
 
It's a few lines of code. You're not asking for an example. You're asking me to write the code for you. I've provided very clear instructions. How about you make the effort to write the code for yourself, then post back with what you've done if you encounter an actual issue? You don't know that you can't do it if you don't try.
 
I provided you with instructions to solve the problem you asked about in this thread. Are you going to make the effort to follow those instructions or not? If you are then I will be happy to help further if you have trouble doing so. If you're not prepared to make that effort on your own behalf, it doesn't encourage me to make the effort that you won't. It's a fact that the best way to learn is to do and my main concern is that you learn, so I expect you to do as much as you can. If you can't do something then that's fine. If you won't do something then that's another matter.
 
I liked the forum and became a member. But extremely disappointing... I'm closing my membership.

Good Forums.
 
So you're unwilling to follow instructions and will accept nothing less than someone else writing your code for you? That's your prerogative, but extremely disappointing.
 
Back
Top Bottom