Ticket Q304230
Visible to All Users

How to simple databind a LookupEdit when the EditValue is not in the underlying DataSource

created 14 years ago

Hello,
I have a scenario where I am using a repositoryItemLookupEdit in a XtraGrid column to allow the user either chooses a value from a list or typing in a new value, and in latter case, I handle the ProcessNewValue event, but the new value is not persisted to the database table used in the LookupEdit complex data binding - it is only stored in the data store of the grid's DataSource as an one-off value.
The issue I am having is that the next time when I load the grid, the column value is not showing up anymore, which I assume is because the data column value does not exist in the LookupEdit DataSource, and since this is done through data binding, I don't have ProcessNewValue event being triggered and therefore has no option to add the value to the DataSource of the LookupEdit.
The behavior that I am looking for is similar to a standard ComboBox with its Text property bound to a BindingSource, but I cannot figure out how to do it with the LookupEdit.
Thanks.

Show previous comments (4)
DevExpress Support Team 14 years ago

    Hi Song,
    So, you don't need to save a text in a data source, you just need to have a possibility to select a value from a list or enter a text and use it somewhere. This can be done easily. You can handle the ProcessNewValue event and assign the e.DisplayValue to the Properties.NullText property. Here is the code snippet showing how this can be done:

    C#
    private void lookUpEdit1_ProcessNewValue(object sender, ProcessNewValueEventArgs e) { lookUpEdit1.Properties.NullText = (string)e.DisplayValue; e.Handled = true; }

    Thanks,
    Ted

    ?
    Unknown 14 years ago

      Hi Ted,
      The problem is not entering a text, which works using ProcessNewValue event as you suggested. The question I am trying to raise is that when simple data bind the value to the LookupEdit again, using the following code

      C#
      lookupEdit.DataBindings.Clear(); lookupEdit.DataBindings.Add("EditValue", bindingSource, fieldName);

      ProcessNewValue is not triggered in the above case, and so there is no option to have the field value show up in LookupEdit.
      Comparing the above to simple databind a standard ComboBox in .Net BCL

      C#
      comboBox.DataBindings.Clear(); comboBox.DataBindings.Add("Text", bindingSource, fieldName);

      The value bound to the Text property in the ComboBox does not have to be in the underlying Items list and it would still show up in the ComboBox to be edited.
      How can I replicate the above behavior of the ComboBox in LookupEdit?
      Thanks.

      DevExpress Support Team 14 years ago

        Hi Song,
        I'm afraid, you cannot. Our lookup controls don't support this functionality. All you can do is to use the ComboBoxEdit and fill its Items collection from the data source.
        Thanks,
        Ted

        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.