473,466 Members | 1,354 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

listbox events

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

Jul 22 '05 #1
3 1418
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.

--
Cheers,

Jonathan
"amber" wrote:
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

Jul 22 '05 #2

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

Jul 22 '05 #3
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.
--
Cheers,

Jonathan

"amber" wrote:

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

Jul 22 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: Oddball | last post by:
Ok - I have a ListBox control and I'm ready to write my own DrawItem event handler. What I want to draw as the item is another control. I have created a user control that I would like to list in...
18
by: Dave Sauny | last post by:
Ok, its a friday, I'm at work and I cant get this to work: I have 3 listboxes on one tab control page. when i select an item in listbox1 i want whatever is selected on the other 2 listboxes...
2
by: Rlrcstr | last post by:
I'm rolling my own with a listbox. The items in the list box are of varying sizes and I'm hit checking when the litbox is checked to see what portion of an item the user has clicked on. Mostly...
3
by: Alec MacLean | last post by:
Hi everyone, I have a ComboBox that when changed, calls a method to change the content of a ListBox. I'm also using the Listbox's SelectedIndexChanged event to change other control values on...
1
by: tony | last post by:
Hello! If you drag a ListBox into a windowform and then right click on this ListBox and then chose property. When you have the properties up click on the flash symbol for seeing all the events...
2
by: Steve Potter | last post by:
I am trying to find some method of attaching a Listbox object to a list object so as the contents of the list are changed the contents of the Listbox will be updated to match. I have found a few...
18
by: Zytan | last post by:
I want the same function to be run whether you press Enter or double click the listbox. It seems really verbose to write both handlers to both events everytime, even if they both call the same...
2
by: =?Utf-8?B?Sm9hY2hpbQ==?= | last post by:
I have tried to use a ListBox with SelectionMode set to MultiSimple. I have also tried quite a lot of the event handlers, but no events seem to be triggered. Why aren't the events triggered?
6
by: Dom | last post by:
In some programs, I see that certain items in a listbox have been grayed, to indicate that they are "there" but can not be chosen. This is very helpful. Can you do this in CSharp? Is there a...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.