Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Windows Forms / WinForm General / June 2007

Tip: Looking for answers? Try searching our database.

ListView's SelectedIndexChanged overfiring -> time for new AfterSelectedIndexChanged event?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Fizgig - 18 Jun 2007 10:45 GMT
I have a ListView control and based on the item selection, another
control is updated. That update process is relatively slow.

I subscribed to the selectedindexchanged event, but that event is not
really helpfull in my case as it fires twice for every change in the
selection, once for clearing the selection and once for adding the new
selected item.

As I allow multiple selections, this is even worse (10 or 11 events
when you select 10 items, depending on your initial state).

What I need is a AfterSelectedIndexChanged event, but without access
to the source I'm not sure what's the best way to fake this.

Any thoughts?
DArnold - 18 Jun 2007 11:04 GMT
> I have a ListView control and based on the item selection, another
> control is updated. That update process is relatively slow.
[quoted text clipped - 11 lines]
>
> Any thoughts?

Set a bflag and use it in the event to bypass the code in the event. You
know the conditions when the event is firing so bypass the code in the
event, by setting the bflag = true. The only time you want the code in
the event to execute is when someone makes a selection and not because
you're loading the Listbox or clearing the Listbox. After the load  or
clearing of the Listbox, you set bflag = false.

if not bflag = true then
   execute the code in the event
else
   bypass the code execution.
Fizgig - 18 Jun 2007 11:27 GMT
> > I have a ListView control and based on the item selection, another
> > control is updated. That update process is relatively slow.
[quoted text clipped - 23 lines]
> else
>     bypass the code execution.

HI darnold,

My problem is that the process "someone makes a selection" is an
atomic process when using the listview selectedindexchange event:
there is no easy way of determining whether more selectedindexchanged
events are going to be fired or not.

So, if that would be possible, i could skip the processing of all
selectedindexchanged events but one in the way you proposed.
Mr. Arnold - 18 Jun 2007 18:13 GMT
Every time you deal with that Listview,  you are loading the Listview with
items, clearing it, or a user makes a selection, the selectedindexchange
event is going to firer.

You know when it's being loaded and you know when it's being cleared. So if
you know these things and the area of the code where you are doing these
things, you set the flag to bypass the code in  the event and set the flag
to not bypass when these things are completed.

If the flag is setting at not bypass, it's because your code at the area of
loading and clearing the Listview has completed its task and set the flag.

Anytime after the tasks above  of loading and clearing are completed with
the area of code setting the flag to not bypass, it will be someone making a
selection that caused the event to fire and the code will be executed.

When you're loading and clearing, set the flag to bypass. When you're done
with loading and clearing, set the flag to not bypass.

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.