Ticket Q299646
Visible to All Users

LookUpEdit doesn't update the CurrencyManager.Position property

created 14 years ago

Hello,
I'm evaluating DevExpress controls for windows forms and I have just one problem, I already use the LookUpEdit control and make it work just like the standar combobox with DataSource binding to custom entities.
The issue is that I use a BindingSource control to fill the DataSource property of my LookUpEditControl and when I change the selected item of the LookUpEdit control the BindingSource is not synchronized with the LookUpEdit control. I mean, the property Position and Current of the BindingSource should be the same as the property ItemIndex and the result of Properties.GetDataSourceRowByKeyValue and also the BindingSource.CurrentChanged event doesn't get fired.
With the traditional ComboBox the combo and the binding source are always synchronized. Last, I think that the combos provided by the XtraEditors Library should behave exactly and with the same properties of binding source, data source, value memeber, display member, selected item, etc… all that properties that we are used to read and write for databinding purposes.

Comments (2)
DevExpress Support Team 14 years ago

    Hi Ricardo,
    Thank you for contacting us.
    To solve the problem, please handle the LookUpEdit.EditValueChanged Event event in the following manner:

    C#
    void lookUpEdit1_EditValueChanged(object sender, EventArgs e) { int index = lookUpEdit1.Properties.GetDataSourceRowIndex(lookUpEdit1.Properties.ValueMember, lookUpEdit1.EditValue); bs.Position = index; }

    See the attached project.
    Thanks
    Dimitros

      Hi Dimitros,
      The problem with this solution is repeating this lines of code in every LookUpEdit with a bindingsource control.
      Before reading your post I made a form baseclase who adds handlers to every LookUpEdit control for the EditValueChanged event. The code inside the event look like this:
          Private Sub LookUpEdit_EditValueChanged(ByVal sender As Object, ByVal e As EventArgs)
              Dim lLookUpEdit As DevExpress.XtraEditors.LookUpEdit = CType(sender, DevExpress.XtraEditors.LookUpEdit)
              If lLookUpEdit.ItemIndex >= 0 AndAlso TypeOf lLookUpEdit.Properties.DataSource Is BindingSource Then
                  CType(lLookUpEdit.Properties.DataSource, BindingSource).Position = lLookUpEdit.ItemIndex
              End If
          End Sub
      After seeing you code I have some questions, There's a difference between the property ItemIndex and GetDataSourceRowIndex?, Do I have to check ItemIndex > 0 or it always gets a valid index if the event is raised?

      Answers approved by DevExpress Support

      created 14 years ago (modified 11 years ago)

      Hi Ricardo,
      The LookUpEdit.ItemIndex property uses the RepositoryItemLookUpEdit.GetDataSourceRowIndex method internally. So, you can use them in the same manner.
      The LookUpEdit.ItemIndex property can return -1 in some cases, for instance, when the LookUpEdit's edit value is set to Nothing.
      Also, you can create a LookUpEdit descendant as described in the Custom Editors help article, override its OnEditValueChanged method, and set the BindingManagerBase.Position property there:

      Visual Basic
      Protected Overrides Sub OnEditValueChanged() MyBase.OnEditValueChanged() Dim manager As BindingManagerBase = BindingContext(Properties.DataSource) manager.Position = ItemIndex End Sub

      We hope that you find this information helpful.
      Thanks,
      Svetlana

        Show previous comments (2)
        DevExpress Support Team 11 years ago

          Hi,
          Yes, the solution is the same for the LookUpEdit in version 13.1. Do not hesitate to contact us if you have any questions or concerns.

          SJ SJ
          Sandeep Jakhotya 4 years ago

            Hello!
            This is the problem to many
            I read the Binding Source position auto Update (as with widows comboBox) feature removed from Ver.10.2 to improve performance.
            So why don't you introduce new Boolean Property in designer saying UpdateBindingSourcePositionOnEditValueChanged and let do it internally.

            We are upgrading from traditional controls to new advanced Dev controls to make life simple,
            positioning BindingSource mannualy requires additional line of codes for all controls in form for every form in the project which is boring.

            Nadezhda (DevExpress Support) 4 years ago

              Hello,

              Our LookUp editor shows data from a related table. So, in most cases, there is no need to synchronize it with the Currency Manager. Moreover, this editor can be used in in-place mode, and in this case, there is no simple way to work with the Currency Manager. That is why the editor's behavior is different from the behavior of the default .NET ComboBox. LookUpEdit doesn't synchronize its edit value with BindingManagerBase.

              In any case, thank you for sharing your idea. I will forward it to our team, and we will analyze possible ways to add a similar option in the future.
              In the meantime, you can manually change the BindingManagerBase.Position property value as Svetlana suggested.

              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.