Results 1 to 13 of 13

Thread: prevent object event from firing

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Aug 2006
    Posts
    734

    prevent object event from firing

    Hi guys,
    I have a combobox that i want to (when my program loads) set to a default selectedindex value. Is there any way i can do this without the selectedIndexChanged event from firing. The reason i need this is because i have code in the the event but i dont want it to run unless the user changes the index manually (not while its done at runtime in the code)? If this isn't possible then is there another way around my problem?

    Thanks in advance for any help
    If your problem has been solved then please mark the thread [RESOLVED].
    If i have helped then please Rate my post

  2. #2
    Frenzied Member stimbo's Avatar
    Join Date
    Jun 2006
    Location
    UK
    Posts
    1,739

    Re: prevent object event from firing

    You could simply have a boolean value. On the index changed routine check first for it. If it's true then exit sub and it wont execute the code.
    Stim

    Free VB.NET Book Chapter
    Visual Basic 2005 Cookbook Sample Chapter

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    Aug 2006
    Posts
    734

    Re: prevent object event from firing

    Bingo! Thats what i was looking for.....thanks for that....i'll try it out and let you know whether it works.
    Thanks again.
    If your problem has been solved then please mark the thread [RESOLVED].
    If i have helped then please Rate my post

  4. #4
    VB Addict Pradeep1210's Avatar
    Join Date
    Apr 2004
    Location
    Inside the CPU...
    Posts
    6,614

    Re: prevent object event from firing

    There's a much easy way...

    Use AddHandler to associate any procedure to an event and RemoveHandler to disassociate anytime in your program at your will.

    Pradeep
    Pradeep, Microsoft MVP (Visual Basic)
    Please appreciate posts that have helped you by clicking icon on the left of the post.
    "A problem well stated is a problem half solved." — Charles F. Kettering

    Read articles on My Blog101 LINQ SamplesJSON ValidatorXML Schema Validator"How Do I" videos on MSDNVB.NET and C# ComparisonGood Coding PracticesVBForums Reputation SaverString EnumSuper Simple Tetris Game


    (2010-2013)
    NB: I do not answer coding questions via PM. If you want my help, then make a post and PM me it's link. If I can help, trust me I will...

  5. #5

    Thread Starter
    Fanatic Member
    Join Date
    Aug 2006
    Posts
    734

    Re: prevent object event from firing

    Its only when i create the combobox at run-time that i dont want it to fire because i am going to default the index, so would it be worth using RemoveHandler.....i haven't got round to trying out either method yet so i'd appreciate some more input if anybody has any.

    Thanks again for all the help so far!
    If your problem has been solved then please mark the thread [RESOLVED].
    If i have helped then please Rate my post

  6. #6
    VB Addict Pradeep1210's Avatar
    Join Date
    Apr 2004
    Location
    Inside the CPU...
    Posts
    6,614

    Re: prevent object event from firing

    It can be used for both controls created at design time or runtime.

    It's easier than you think. Just try it once ad see for yourself.


    Pradeep
    Pradeep, Microsoft MVP (Visual Basic)
    Please appreciate posts that have helped you by clicking icon on the left of the post.
    "A problem well stated is a problem half solved." — Charles F. Kettering

    Read articles on My Blog101 LINQ SamplesJSON ValidatorXML Schema Validator"How Do I" videos on MSDNVB.NET and C# ComparisonGood Coding PracticesVBForums Reputation SaverString EnumSuper Simple Tetris Game


    (2010-2013)
    NB: I do not answer coding questions via PM. If you want my help, then make a post and PM me it's link. If I can help, trust me I will...

  7. #7
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: prevent object event from firing

    There's an even easier way. Don't handle the SelectedIndexChanged event. The SelectedIndexChanged event is raised whenever the SelectedIndex property changes. If what you actually want to detect is when the user makes a selection then the appropriate event to handle is SelectionChangeCommitted.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  8. #8

    Thread Starter
    Fanatic Member
    Join Date
    Aug 2006
    Posts
    734

    Re: prevent object event from firing

    Is that event supported with the .net compact framework?
    If your problem has been solved then please mark the thread [RESOLVED].
    If i have helped then please Rate my post

  9. #9
    Frenzied Member
    Join Date
    Mar 2005
    Location
    Sector 001
    Posts
    1,577

    Re: prevent object event from firing

    Nope, it isn't.
    VB 2005, Win Xp Pro sp2

  10. #10

    Thread Starter
    Fanatic Member
    Join Date
    Aug 2006
    Posts
    734

    Re: prevent object event from firing

    Ok kool....i know i didn't specify i was using cf but i didn't think it would be necessary....so apologies to anyone who gave advice that i cant use!
    If your problem has been solved then please mark the thread [RESOLVED].
    If i have helped then please Rate my post

  11. #11
    Frenzied Member
    Join Date
    Mar 2005
    Location
    Sector 001
    Posts
    1,577

    Re: prevent object event from firing

    http://msdn2.microsoft.com/en-us/library/719dt662.aspx

    I wouldn't mind a full CF. The modern handhelds are powerfull enough and their optimized hardware easily beats a 'Pentium 133 MHz' & '256 MB'.
    VB 2005, Win Xp Pro sp2

  12. #12
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: prevent object event from firing

    Always specify your version and always specify that you're using the CF unless you post in the dedicated Mobile forum.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  13. #13
    Member
    Join Date
    Jun 2006
    Location
    Chennai, INDIA
    Posts
    58

    Smile Re: prevent object event from firing

    Dim bFormloadInProgress As Boolean in the form that has the control.

    When you enter form load set bFormloadInProgress = True and when you are about to exit the form load event. set bFormloadInProgress = False

    In selectedIndexChanged event use the foll code at the beginning

    If bFormloadInProgress = True Then
    Exit Sub
    End If

    Hope this helps.

    Sugan.
    Sugan
    Chennai, INDIA.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width