473,378 Members | 1,527 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

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 1416
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...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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...

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.