Current filter:
                                You should refresh the page.
                                Support Center
                                0
                                  • Hi,

                                    I have 2 checkboxes "a" and "b". I have to uncheck "b" if "a" is selected and vice versa.I tried to handle this in checkedchange eventhandler for both the checkboxes.But it doesnt maintain its state on single click sometimes. I will have to click checkbox twice inorder to maintain its state sometimes and other times it maintains its state on single click. Checkboxes are not inside a gridview.Also checkbox is bound to a datasource.Here is the code snippet.


                                    private void a_CheckedChanged(object sender, EventArgs e)
                                    {
                                    b.CheckedChanged -= b_CheckedChanged;

                                    if (b.Checked)
                                    {
                                    b.Checked = false;

                                    }
                                    b.CheckedChanged += b_CheckedChanged;

                                    }

                                    private void b_CheckedChanged(object sender, EventArgs e)
                                    {
                                    a.CheckedChanged -=a_CheckedChanged;

                                    if (a.Checked)
                                    {
                                    a.Checked = false;

                                    }
                                    a.CheckedChanged += a_CheckedChanged;

                                    }


                                You must  log in  or  register  to leave comments

                                2 Solutions

                                Creation Date
                                Rating
                                Importance
                                Sort by
                                0

                                To achieve this goal you can simply specify CheckEdit.Properties.RadioGroupIndex property for these editors.

                                You must  log in  or  register  to leave comments
                                0

                                Thank you for your quick response.This didnt fix the issue.After I set the same Radiogroupindex I am unable to unselect the checked value by clicking on it.I have to clickthe other checkbox to unselect.Is it possible to select and unselect by clicking on the same checkbox and still behave mutually exclusive?

                                • Hi,
                                  This is correct behavior, because in this case the check boxes operate like a RadioGroup. Since radio buttons are mutually exclusive, a check editor that functions in radio button mode can accept only two states - checked or unchecked. When the user selects a check editor within the group, the editor's state becomes checked and other editors are unchecked automatically.

                                  I believe this behavior is more logical if you wish to implement the radio group functionality. However, if you do not want the check boxes to be mutually exclusive, handle the CheckEdit.EditValueChanged event for both the check boxes in the following manner:

                                   private void checkEdit4_EditValueChanged(object sender, EventArgs e) {
                                              CheckEdit checkEdit = sender as CheckEdit;
                                              if (checkEdit.Name == "checkEdit3")
                                                  checkEdit4.Checked = !Convert.ToBoolean(checkEdit.EditValue);
                                              else
                                                  checkEdit3.Checked = !Convert.ToBoolean(checkEdit.EditValue);
                                          }

                                  In addition, I have created a sample based on your description, please find it in the attachment.

                                  I hope this solution will be helpful to you. Let us know your results.

                                You must  log in  or  register  to leave comments

                                To start a chat you should create a support ticket


                                If you need additional product information, write to us at info@devexpress.com or call us at +1 (818) 844-3383

                                FOLLOW US

                                DevExpress engineers feature-complete Presentation Controls, IDE Productivity Tools, Business Application Frameworks, and Reporting Systems for Visual Studio, along with high-performance HTML JS Mobile Frameworks for developers targeting iOS, Android and Windows Phone. Whether using WPF, Silverlight, ASP.NET, WinForms, HTML5 or Windows 8, DevExpress tools help you build and deliver your best in the shortest time possible.

                                Copyright © 1998-2014 Developer Express Inc.
                                All trademarks or registered trademarks are property of their respective owners