Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
1210
Ultra Combo Value Change event on Form Close
posted

Hi Mike,
               I have one ultra combo and Windows ComboBox in one winform with following settings :

       
private void Form1_Load( object sender, EventArgs e )
        {
          //creating dummy data
            DataTable dt = new DataTable();
            DataColumn col = new DataColumn( "ID", typeof( int ) );
            dt.Columns.Add( col );
            col = new DataColumn( "Name", typeof( string ) );
            dt.Columns.Add( col );

            DataRow row = dt.NewRow();
            row [ 0 ] = 1;
            row [ 1 ] = "aa";
            dt.Rows.Add( row );
            row = dt.NewRow();
            row [ 0 ] = 2;
            row [ 1 ] = "bb";
            dt.Rows.Add( row );

            dt.AcceptChanges();           

            DataTable business = new DataTable();
            col = new DataColumn( "BID", typeof( int ) );
            business.Columns.Add( col );
            row = business.NewRow();
            row [ 0 ] = 2;
            business.Rows.Add( row );

            //Win combo
            this.comboBox.DataSource = dt;
            this.comboBox.DisplayMember = "Name";
            this.comboBox.ValueMember = "Id";
            this.comboBox.DataBindings.Add( "SelectedValue", business, "BID", true, DataSourceUpdateMode.OnPropertyChanged );
            this.comboBox.SelectedValue = -1;
            this.comboBox.SelectedValueChanged += new EventHandler( comboBox1_SelectedValueChanged );

            //Ultra combo
            ultraCombo.AllowNull = Infragistics.Win.DefaultableBoolean.True;
            ultraCombo.NullText = "Unassigned";           
            ultraCombo.DataSource = dt;
            ultraCombo.ValueMember = "Id";
            ultraCombo.DisplayMember = "Name";
                       
            ultraCombo.DataBindings.Add( "Value", business, "BID", true, DataSourceUpdateMode.OnPropertyChanged );
            ultraCombo.Value = null;
            ultraCombo.ValueChanged += new EventHandler( ultraCombo_ValueChanged );
        }

        void comboBox1_SelectedValueChanged( object sender, EventArgs e )
        {
            MessageBox.Show( "Win : selected index changed" );
        }

        void ultraCombo_ValueChanged( object sender, EventArgs e )
        {
            MessageBox.Show( "Ultra combo : selected index changed" );
        }

If focus is in UltraCombo and selected value is null, On Close of form it is firing ValueChange event.
I tried same thing with windows ComboBox and it works fine(It wont fire value change event on form close).
Is there any way to stop this thing? Because in ValueChange event I am setting some flags and based on it I am showing warning message to save the changes. In my case without doint anything if we close form it is asking for Save.
Please reply me as soon as possible.

--
Thanks,
Ganesh
  • 7570
    posted

    Hello Ganesh,

    The issue is arising because the UltraCombo is bound to a datasource and its Value property is set programmatically to Null.

    Databinding does not handle programmatic changes to UI controls. The BindingManager does not track changes on the controls that do not have focus. The BindingManager expects that the only changes it should track are those made by the user.

    If the bound field needs to be updated or set, we recommend the following (in order of preferrence):

     1. Set the value of the field in the DataRow and do not make programmatic changes to the data via the UI Controls.

    OR

    2. Use DBNull.Value instead of null. DBNull.Value is not the same as null. (This is why the ValueChanged event was fired).

     

    Please let me know if you have further questions regarding this issue or suggested solutions.

     

    Thank you for choosing Infragistics

     

  • 7570
    posted

    Hello Ganesh,

    I have created a private support case for you, and linked it to Development Issue 72406.

    I will update you further through the support case.

     

  • 469350
    Offline posted

    Hi Ganesh,

    I tried this out using your sample code and I get the same results you describe. The BindingManager is setting the Value of the UltraCombo to null when it loses focus. But since the value of the control was already null, it seems like there is something wrong here and it should not be firing the event.

    I'm going to forward this thread over to Infragistics Developer Support and ask them to open a case for you and write this up as a bug for developer review.

    In the mean time, you could work around this issue very easily by unhooking from the ValueChanged event in the Form_Closing or Form_Closed events. Both events are fired before the ValueChanged event fires in my testing.