Change Events

2 posts, 0 answers
  1. Sean Overman
    Sean Overman avatar
    31 posts
    Member since:
    Sep 2012

    Posted 01 Jun 2011 Link to this post

    I'm currently developing an application with branches in both Web AND WinForms.   The application started as a Web App, and now is currently being migrated to WinForms.

    One problem I've encountered NUMEROUS times now, is that when building a webform, the change events don't fire during the initialization and setup of the controls, but in WinForms, if i've attached to a change event of some control, when I am building the form programaticly during setup and setting values on things(dropdowns, checkboxs), these events fire.  (this is undesired)

    The counter measure I've applied so far is to have a class level variable named something like _changeMadeFromCode then whenever I want to set the value of a control, I have to set var to true, set the value on the control, the set the var back to false.  Then inside of the event handler, I have to check for the bool and only perform that actions if the var is false.

    This works obviously, but it becomes tedious and slightly annoying to implement.

    I realize that this is by design in the dotNet framework, I was working if anyone else has come up with a more elegant solution?
  2. Peter
    Peter avatar
    1148 posts

    Posted 07 Jun 2011 Link to this post

    Hi Sean,

    Thank you for the writing.

    The WinForms and ASP.NET applications have different life cycle and this behavior is normal.
    Your workaround with boolean flag is acceptable, but I would like to suggest another solution - you should subscribe to the events after the application is shown on FormLoad (or FormShown) event.
    For example:


    protected override void OnLoad(EventArgs e)
                this.radDropDownList1.SelectedIndexChanged += new Telerik.WinControls.UI.Data.PositionChangedEventHandler(radDropDownList1_SelectedIndexChanged);
            void radDropDownList1_SelectedIndexChanged(object sender, Telerik.WinControls.UI.Data.PositionChangedEventArgs e)
    Protected Overrides Sub OnLoad(e As EventArgs)
        AddHandler Me.radDropDownList1.SelectedIndexChanged, AddressOf radDropDownList1_SelectedIndexChanged
    End Sub
    Private Sub radDropDownList1_SelectedIndexChanged(sender As Object, e As Telerik.WinControls.UI.Data.PositionChangedEventArgs)
    End Sub

    I hope this helps.

    the Telerik team
    Q1’11 SP1 of RadControls for WinForms is available for download; also available is the Q2'11 Roadmap for Telerik Windows Forms controls.
  3. DevCraft R3 2016 release webinar banner
Back to Top