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
Parents
  • 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

     

Reply Children