listbox events

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hello,

I'm having trouble findingwhich event I need to use with a listbox.

When a user selects a new item in the listbox, I want to trigger an event
BEFORE the new item is actually selected.

I've tried _Validating, but that doesn't seem to do the trick...

Any suggestions?

Thanks!
Amber
 
Hi Amber,

I'm curious as to whether you are building a Windows or Web Forms Application?

The Windows Forms version of the listbox provides a much more robust set of
events that you can hook into to get you desired behavior (Possibly the
MouseEnter...?).

Web Forms are usually somewhat more challenging, you may need to use some
client-side scripting in order to get your desired results.
 
Hi there.
I'm using Windows Forms.
Maybe I'm going about this in the wrong way.
What I'm doing is this:
I have a listbox on a form with a bunch of text boxes. The values in the
textboxes are linked to what is selected in the listbox.
If a user edits any of the textboxes, then tries to move off the current
item in the listbox, I need to prompt to save, then save the current record.
My problem is, the new item in the listbox is already selected at this
point...
Make sense?
Cheers,
Amber
 
I think I see what you are are trying to accomplish.

Can you store your listboxes selectedIndex as a Form (or class) level
declaration?

You can then hook into the SelectedIndexChanged event on your listbox, some
pseudo code would look like this:

// class or form level declarations
int lastSelectedIndex=0
bool textBoxesChanged=false

On textbox_TextChanged
-set textBoxesChanged=true

On listbox_OnSelectedIndexChanged
-if textBoxesChanged == true
-if prompt for save == yes
-do a save for the object referred to by lastSelectedIndex by retrieving
data from
textboxes
-set textBoxesChanged=false
-set lastSelectedIndex = listbox.SelectedIndex
-load up textboxes with new selected item's data

Done

You might use SelectedValue instead of selected index if your listbox values
are referencing objects in an array or database...

Hope it helps.
 
Back
Top