Newbie: click event on ListBox item(s)

  • Thread starter Thread starter steve
  • Start date Start date
S

steve

Hello,

how can i check for something like this ?
I can't seem to find anything relevant (method/property).

What i want to do is after I fill up a listbox with elements (file names
coming from OpenFileDialog), i want to aloow the user to remove some of them
simply by clicking on them. I managed to fill up the listbox but i am stack
on the second part.

Any hints would be appreciated.
Thanx In advance
-steve
 
There may be a way, but I dont think so. The control does not seem to have
that as a public event. Another way to do this is to create your own control
( User control ) with this functionality, you know a listBox and couple of
buttons, and a bit of code underneath, this way you can declare a public
event which is rasied when the user clicks on an entry in the listbox, I
think this is probably the best way.

HTH

--

OHM ( Terry Burns )
. . . One-Handed-Man . . .
If U Need My Email ,Ask Me

Time flies when you don't know what you're doing
 
private sub listbox1_doubleclick(byVal sender as object, byVal e as
System.EventArgs) _
handles listbox1.doubleclick
dim p as System.Drawing.Point = Cursor.Position
dim index as Integer = listbox1.FromPoint(p)
listbox1.Items.RemoveAt(index)
end sub

On second thoughts, I suppose you could even use the SelectedItem to remove;
just replace all the lines above with this:
listbox1.Items.Remove(listbox1.SelectedItem)

hope this helps..
Imran.
 
Ignore this post, I misread it, I thought you wanted to remove the items in
the OpenDialog box.

--

OHM ( Terry Burns )
. . . One-Handed-Man . . .
If U Need My Email ,Ask Me

Time flies when you don't know what you're doing
 
oops..sorry. Didn't read the question right. Ofcourse, since you want it on
the click, Terry's answer is more relevant.
However, I don't think thats a very good idea; If a user happens to click
one of the items by mistake, thats going to be a problem. The height of the
listitems isn't a lot and I'm pretty sure users could click on the wrong
item by mistake.

Imran.
 
Ok..I think I really need some coffee to get me through this afternoon.
I haven't tried this but you could do
listbox1.RemoveAt(listbox1.SelectedItem) in the SelectedIndexChanged event
of the listbox to accomplish what you want. However, that would also mean
the item would be removed even if you selected the item using your keyboard.
I'm not sure whether you would want it that way.

hope this helps..
Imran.
 
As a user, I wouldn't find it very user-friendly to have the items removed
simply by clicking. I would rather see a remove button with the option of
double clicking the lstbox having the same effect.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top