This is a migrated thread and some comments may be shown as answers.

Change Events

1 Answer 75 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Sean Overman
Top achievements
Rank 1
Sean Overman asked on 02 Jun 2011, 01:08 AM
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?

1 Answer, 1 is accepted

Sort by
0
Peter
Telerik team
answered on 07 Jun 2011, 03:27 PM
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:

C#

protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);
            this.radDropDownList1.SelectedIndexChanged += new Telerik.WinControls.UI.Data.PositionChangedEventHandler(radDropDownList1_SelectedIndexChanged);
        }
 
        void radDropDownList1_SelectedIndexChanged(object sender, Telerik.WinControls.UI.Data.PositionChangedEventArgs e)
        {
             
        }
Vb.Net
Protected Overrides Sub OnLoad(e As EventArgs)
    MyBase.OnLoad(e)
    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.

Regards,
Peter
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.
Tags
General Discussions
Asked by
Sean Overman
Top achievements
Rank 1
Answers by
Peter
Telerik team
Share this question
or