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.
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.
Hi Song,
I presume that you use DataSet (or DataTable) as a data source for LookupEdit. In this case, when you add a value to the data source, it is not stored in the data storage automatically. You should call the DataAdapter's (or TableAdapter's) Update method to store data. This is how .Net Framework DataSet works. Please refer to the following MSDN help topic to learn more How to: Update Records in a Database
Thanks,
Ted
Ted,
Thanks for the reply. However, the business requirement is that the new value that the user typed in the LookupEdit should not be stored in the underlying database (the pre-defined list comes from another source, and the new value is treated as a one-off, much like one may have an address book while can also type in a one-off email address without having to save it back to the address book.)
What I am looking for is either 1) how to simple data bind (to the EditValue property of the LookupEdit I suppose) with a value that is not in the LookupEdit dataSource; or if that is not possible 2) Any event handle triggered during simple data binding (not complex data binding to dataSource, DisplayMember and ValueMember) to detect a value bound is not in the underlying list, therefore allowing me to add it to the list (DataTable only, not back to the database.)
Regards,
Hi Song,
Thank you for the clarification. Now, I understand what you're trying to achieve. However, LookupEdit cannot be used this way. It can work only with a data source, Binding can be used to supply an EditValue (for which the Display value will be found from the data source). So, I suggest another solution. If you use DataSet, you can simply add values there. If you do not save them to an initial data storage, these values will be erased next time you load data via the Fill method. If you use a list of some objects, you can make a copy, and use it as the data source.
Thanks,
Ted
Ted,
Thanks for the reply. Unfortunately your suggestion does not work for my scenario because that would require me to modify the DataSet to include all the one-off values in the system in the DataTable prior to binding, which is both expensive and unnecessary for display purpose (as I don't need those one-off values to be included in the drop down list.)
Since it is something that can be easily achieved with a standard ComboBox, it perplexes me why DevExpress chose not to offer a control that functions similarly to a regular ComboBox and works with XtraGrid in its extensive lineup of XtraEditors control? I understand LookupEdit is designed for a different purpose and therefore may not make sense to mix the functionality here. I know the ComboBoxEdit is another option, but the choice to not support complex databinding there is equally perplexing.
Thanks.
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:
private void lookUpEdit1_ProcessNewValue(object sender, ProcessNewValueEventArgs e) { lookUpEdit1.Properties.NullText = (string)e.DisplayValue; e.Handled = true; }
Thanks,
Ted
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
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
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.
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