Hello Support,
We are using a xamDataGrid with two xamComboEditor columns. We have added the 'SelectedItemChanged' event to xamComboEditors at design time using event setters.
<Window.Resources>
<igEditors:ComboBoxItemsProvider x:Key="ComboItemsProviderService"/>
<Style x:Key="ServiceFieldStyle" TargetType="{x:Type igEditors:XamComboEditor}">
<Setter Property="ItemsProvider" Value="{StaticResource ComboItemsProviderService}" />
<EventSetter Event="SelectedItemChanged" Handler="ServiceType_SelectedItemChanged"/>
</Style>
<igEditors:ComboBoxItemsProvider x:Key="ComboItemsProviderSplitNum"/>
<Style x:Key="SplitNumFieldStyle" TargetType="{x:Type igEditors:XamComboEditor}">
<Setter Property="ItemsProvider" Value="{StaticResource ComboItemsProviderSplitNum}"/>
<EventSetter Event="SelectedItemChanged" Handler="SplitNumber_SelectedItemChanged"/>
</Window.Resources>
When we assign data source to the xamDataGrid, we do not want the 'SelectedItemChanged' event to be called. Can you please suggest a way by which the 'SelectedItemChanged' event is not fired when data source is assigned to the grid.
Waiting for your reply.
Thank You.
Hello,
Thank you for your post. I have been looking through it and I created a sample project for you with the functionality you need. Basically I handled the XamComboEditor’s Loaded event and in it I registered the handler for the SelectedItemChanged event. Please let me know if you need further clarifications on this matter.
Looking forward for your reply.
Thank you for your reply. We implemented the solution suggested by you, however in our application we need to refill the grid every time. For e.g. we have a text box to enter the order number and on the basis of the order number the order details are displayed in the grid. The grid is rebindinded/re-populated on the 'PreviewLostKeyboardFocus' event of the text box (order number). With the code you gave, initially the Selected Item Changed event is not fired when the form is loaded, however subsequently when we rebind the grid (on the basis of the order number) the selected item changed event is fired as soon as an datasource is assigned to the grid. Is there any way to avoid the call to the Selected Item Changed event when the datasource is assigned? We even tried removing the handler before loading the data grid and assigning it back, but it did not work. Also the grid has the 'AllowAddNew' property set to true.
Awaiting your reply.
Thank you.
Hello again,
I have been looking through the sample project you have sent me and I modified it, so now the SelectedItemChanged event is fired only when the use changes it. Basically I set a new Style, based on the existing one before I changed the DataSource and by doing this the Style is rendered after the DataSource loaded which prevent the event from firing. Please let me know if this helps you or you need further clarifications on this matter.
Hello Stefan,
Thank you for the quick reply. We have been trying to implement the changes you suggested in our application. However we realized that even in the sample application you provided, if we assign a 'ValuePath' property to the xamComboEditor, our issue still persists. Also in our application, we are not using ObservableCollection, instead, the xamComboEditor is bound to one dataset and the xamDataGrid is bound to another dataset which contains reference to the values in the xamComboEditor. Hence we need to provide ValuePath, DisplayMemberPath and ItemSource properties to the xamComboEditor and also require the SelectedItemChanged event not being fired when a datasource is assigned to the xamDataGrid.
I am just checking the progress of this issue and was wondering if you managed to achieve your goal or if you need any further assistance on the matter.
Thank you for your reply. The solution you provided works good till the vertical scroll bar does not appear i.e. if the number of records in xamDataGrid are more the SelectedItemChanged event gets called only for the visible records and once you start scrolling the selection change event gets fired for the newly visible records. Because of this, in case the user manually changes the selection of the combo box without having scrolled through all the records, the required code does not execute since the 'isSourceChanged' variable is still not zero. We also tried setting the 'RecordLoadMode' and the 'RecordContainerGenerationMode' properties to 'PreLoad', but could not get through the issue. Also we need the ScrollingMode to be 'Immediate'.
I have been looking into the sample I sent you before and I modified it, so now it works as you want. Please take a look at it and let me know if you need further clarifications on this matter.
Thank you for your feedback. I am glad that you resolved your issue and I believe that other community members may benefit from this as well.
Thanks again.
We managed to achieve the functionality required with your help.