Ticket Q270901
Visible to All Users

Programmatically Clear LookupEdit and Bound Dataset

created 15 years ago

I have looked through the volumes questions about clearing a lookupedit, but haven't found a suggestion to solve the problem I am having.
I have a lookupedit that allows the user use your standard ctrl+del key to clear it and thereby set the underlying data field to null. However, using ctrl+del is not apparent to the user. So I have added a button next to a lookupedit to allow the user to clear the field.
If the clear button handler simply sets the EditValue to null, the entry is cleared in the lookupedit control, however the change is not propagated to the underlying data source. If in addition, I set the underlying data source field to null, then the data source is indeed set to null, however this causes problems with the bindingsource filter; the row is no longer in the filtered set which is bound to the control. This causes the data row displayed to the user to not be the one selected for editing.
How can I programmatically cause that which is done when the user keys ctrl+del while focused on the lookupedit control?

Comments (3)
Anatol (DevExpress) 15 years ago

    Hello Thomas,
    I don't quite understand why setting the editor's EditValue to null brings other results than when pressing the Ctrl+Del hotkey. Almost the same code is executed in our control when this hotkey is pressed. I've attached a sample project where this approach is used, and it appears to work fine. Another solution is to raise the KeyDown event programmatically, via the SendKey method, as shown below:

    C#
    private void repositoryItemLookUpEdit1_ButtonClick(object sender, DevExpress.XtraEditors.Controls.ButtonPressedEventArgs e) { if (e.Button.Kind == DevExpress.XtraEditors.Controls.ButtonPredefines.Minus) { ((LookUpEdit)sender).SendKey(new KeyEventArgs(Keys.Control | Keys.Delete)); } }

    If it doesn't help, please provide a sample project, reproducing the problem.
    Thanks,
    Anatol

      I sorted it out. This difference is that the lookupEdit.EditValue = null was being called in the clear button event handler, i.e. the lookUpedit control did not have focus when its EditValue is set to null. When I add lookupEdit.Focus() to precede setting its edit value to null (in the clear button event handler), I get the expected/desired behavior.
      Thank you.

      Anatol (DevExpress) 15 years ago

        Hello Thomas,
        Thank you for the additional information. In this case, the problem will probably be resolved by calling the LookUpEdit.DoValidate method after setting the EditValue property. From my point of view, this solution is better than setting focus to LookUpEdit. Please let me know whether it works in your project.
        Thanks,
        Anatol

        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.