Ticket DQ16707
Visible to All Users

How can I force a binded value to be committed when changing

created 19 years ago

I'm binding a property of an object to the "Checked" or "EditValue" of a check box, and the value is "committed" to the object only when the check box control loses the focus. I would like the value to be committed as soon as the user changes the value. How can I accomplish this?
This question is also valid for a drop down, if I bind a value to a drop down, in some case I would like the value to be changed as soon as the user changes the values.
Thanks!

Show previous comments (4)
Stan (DevExpress Support) 19 years ago

    Hi Alex,
    If you take a look at my previous post closely, you will notice that I suggested that you handle the EditValueChanged event but not the EditValueChanging. So, I have corrected your sample based upon my previous suggestion and it works just fine now. Please review it and inform me whether this approach suits your needs.
    Thanks,
    Stan.

      I don't know if it's caused by the version 6.2 but I've noticed that if you hook the event EditValueChanged before setting the datasource, the DoValidate has no effect ( ie the data is not commited to the binded property). If you use the sample that you sent and hook the event add the beginning of the simpleButton1_Click method instead of after setting the datasource, you will notice that the event is triggered and the DoValidate is called but the data is not set to the object.

        Clarification : I've noticed that it needs to be hook after the databinding is set, not after the datasource.

        Answers

        created 18 years ago

        Hi Alex,
        Thank you for the feedback. In fact this is a MS data binding issue. If you add the data binding after assigning the EditValueChanged event, this event will fire before the control's DataBinding has been completely initialized. Thus it will not work as expected. As a workaround I can suggest that you perform the postponed validation:
        private void simpleButton1_Click( object sender, EventArgs e )
        {
            List<DataClass> list = new List<DataClass>();
            list.Add( new DataClass( 1, "aa" ) );
            list.Add( new DataClass( 2, "bb" ) );
            list.Add( new DataClass( 3, "ss" ) );
            list.Add( new DataClass( 4, "ww" ) );
            _bo = new BusinessObject( list );
            lookUpEdit1.Properties.DataSource = list;
            lookUpEdit1.EditValueChanged += new EventHandler(lookUpEdit1_EditValueChanged);
            lookUpEdit1.DataBindings.Add(new Binding("EditValue", _bo, "DataID", true));
            textEdit1.DataBindings.Add( new Binding( "EditValue", _bo, "DisplayValue", true ) );
        }
        void lookUpEdit1_EditValueChanged(object sender, EventArgs e)
        {
            BeginInvoke(new MethodInvoker(PerformValidation));
        }
        void PerformValidation()
        {
            lookUpEdit1.DoValidate();
        }
        Please feel free to contact us if you need any additional assistance in this regard. We will be happy to help you.
        Thanks,
        Stan.

          Comments (2)

            I know this is 8 year old post but BRILLIANT!
            i came across lots of other posts that suggested dovalidate but none suggested that it needed to be invoked, as soon as i did that i started working!

            DevExpress Support Team 11 years ago

              I'm happy to hear that our assistance was helpful!
              Feel free to contact us if you have other questions.

              Disclaimer: The information provided on DevExpress.com and affiliated web properties (including the DevExpress Support Center) is provided "as is" without warranty of any kind. Developer Express Inc disclaims all warranties, either express or implied, including the warranties of merchantability and fitness for a particular purpose. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.

              Confidential Information: Developer Express Inc does not wish to receive, will not act to procure, nor will it solicit, confidential or proprietary materials and information from you through the DevExpress Support Center or its web properties. Any and all materials or information divulged during chats, email communications, online discussions, Support Center tickets, or made available to Developer Express Inc in any manner will be deemed NOT to be confidential by Developer Express Inc. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.