Hi ,
I have defined one XamGrid with ComboBoxColumn.
<ig:XamGrid x:Name="ManageRecipeStateGrid" AutoGenerateColumns="False" ColumnWidth="*" ItemsSource="{Binding ManageRecipeStateResults}">
<ig:XamGrid.GroupBySettings>
<ig:GroupBySettings AllowGroupByArea="Hidden" GroupByOperation="MergeCells" />
</ig:XamGrid.GroupBySettings>
<ig:XamGrid.Columns>
<ig:TextColumn Key="RecipeKey" Visibility="Collapsed" />
<ig:TextColumn Key="MandatoryCriteriaList" HeaderText="Recipe" IsReadOnly="True" >
</ig:TextColumn>
<ig:TextColumn Key="RecipeVersion" HeaderText="Version" IsReadOnly="True">
<ig:TextColumn Key="PreviousRecipeState" Visibility="Collapsed" />
<ig:ComboBoxColumn Width="120" HorizontalContentAlignment="Stretch"
ItemsSource="{Binding Source={StaticResource optionList}}" Key="CurrentRecipeState"
SelectedValuePath="State"
DisplayMemberPath="State"
AllowEditingValidation="True" HeaderText="Recipe State">
</ig:ComboBoxColumn>
<ig:CheckBoxColumn Key="IsPreserved" HeaderText="Preserve Recipe">
</ig:CheckBoxColumn>
</ig:XamGrid.Columns>
<ig:XamGrid.EditingSettings>
<ig:EditingSettings AllowEditing="Hover" />
</ig:XamGrid.EditingSettings>
</ig:XamGrid>
Now I want to handle the event whenever I change the item selection in ComboBoxColumn. How I can handle this ?
Hello,
Thank you for your post. I have been investigating how you can handle the selection changed event of the ComboBoxColumns and since the column is using a ComboBox as an editor when the cell is in edit mode, you can handle the SelectionChange event of the ComboBox. To do that, you can handle the CellEnteredEditMode event of the XamGrid and if the cell is of the ComboBoxColumn you can handle the SelectionChanged event. Here is an example for that:
private void ManageRecipeStateGrid_CellEnteredEditMode(object sender, Infragistics.Controls.Grids.EditingCellEventArgs e) { if (e.Cell.Column.Key.Equals("CurrentRecipeState")) { (e.Cell.Control.Content as ComboBox).SelectionChanged += new SelectionChangedEventHandler(MainWindow_SelectionChanged); } } void MainWindow_SelectionChanged(object sender, SelectionChangedEventArgs e) { //Do Something }
Another approach that you can use is creating a TemplteColumn instead of a ComboBoxColumn and in the EidorTemplate you can add a XamComboEdior and handle the SelectedItemChanged event. I have created a sample application for you, based on the code snippet that you have provide, which implements the mentioned approach.
Please let me know if you need any further assistance on the matter.
Sincerely,
Krasimir
Developer Support Engineer
Infragistics
www.infragistics.com/support
Hi,
How to select a selecteditem from combobox.
combobox.sleecteditem properties is not availablethen how we can store the sleecteditem to sql table?
can u give any idea?
thanks
Hello Arpita,
Thank you for your patience while I was looking into the issue that you have described. After further investigation, I have found a different approach, using the SelectedItemChanged event in order to validate the selection of the XamComboEditor. Using this approach, you can revert to the previous selected item when the validation fail and also you can access the Active Row, using the Utilities class. I have modified the sample application I have previously sent to you, in order to demonstrates how you can implement this approach.
Hi Krasimir,
Thanks for the reply . The solution works fine for me. One thing I changed in your solution is instead of using Message box to show the error message I created a Pop control something like this which is like a tooltip so tht user does not have to click evertytime on "OK" button of MessageBox. I have set the StaysOpen property to false so that this message disappears as soon as you click anywhere but problem in this case is this popup box is never disappearing even after setting StaysOpen property to false. I am using this popup across my application but everywhere it disappears as soon as I click anywhere. In this case it is not disappearing. I am attaching my modified solution with this popup implemented. Can you please check this ?
<
="False">
="2">
="LightGoldenrodYellow">
="Stretch" />
>
Thank you for the provided sample application. I have been looking into it and it seems that the reason for the popup that you are displaying, to not hide when you click anywhere within the application is that at the time that the Popup is opened, the popup of the XamComboEditor’s drop down is still open and it catches the mouse down event and the Popup that you are opening does not get notification when you click in the window and t stays open. It seems that this is the expected behavior in wpf platform. You can test this behavior by adding using the following code:
Xaml:
<Window x:Class="WpfApplication1.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="MainWindow" Height="350" Width="525"> <Grid> <Popup x:Name="p1" StaysOpen="False"> <Grid Background="Blue"> <TextBlock Text="asdasd"/> </Grid> </Popup> <Popup x:Name="p2" StaysOpen="False"> <Grid Background="Red"> <TextBlock Text="asdasd"/> </Grid> </Popup> <Button Content="Button" Height="23" HorizontalAlignment="Left" Margin="187,110,0,0" Name="button1" VerticalAlignment="Top" Width="75" Click="button1_Click" /> </Grid> </Window>
C#:
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Windows; using System.Windows.Controls; using System.Windows.Data; using System.Windows.Documents; using System.Windows.Input; using System.Windows.Media; using System.Windows.Media.Imaging; using System.Windows.Navigation; using System.Windows.Shapes; namespace WpfApplication1 { /// <summary> /// Interaction logic for MainWindow.xaml /// </summary> public partial class MainWindow : Window { public MainWindow() { InitializeComponent(); } private void button1_Click(object sender, RoutedEventArgs e) { p1.PlacementTarget = sender as UIElement; p2.PlacementTarget = sender as UIElement; p1.Placement = System.Windows.Controls.Primitives.PlacementMode.Left; p2.Placement = System.Windows.Controls.Primitives.PlacementMode.Right; p1.IsOpen = true; p2.IsOpen = true; } } }
Using this example you can see that one of the popups that are opened at the same time always stay open. What I can suggest is using a Dispatcher, in order to open you popup after the one of the XamComboEditor’s dropdown is closed as follow:
private void XamComboEditor_SelectedItemChanged(object sender, RoutedPropertyChangedEventArgs<object> e) { // (sender as XamComboEditor).SelectedItemChanged -= XamComboEditor_SelectedItemChanged; Data activeRowData = (Utilities.GetAncestorFromType(sender as DependencyObject, typeof(CellControl), false) as CellControl).Cell.Row.Data as Data; if (e.OldValue != null && e.NewValue != null) { Debug.Write("Old: " + (e.OldValue as ComboData).State + " - New: " + (e.NewValue as ComboData).State); if ((e.OldValue as ComboData).State.Equals("State 1") && (e.NewValue as ComboData).State.Equals("State 5")) { // MessageBox.Show("State 5 is not valid when State 1 is selected!!!\nActive MandatoryCriteriaList is: " + activeRowData.MandatoryCriteriaList); Dispatcher.BeginInvoke(new Action(() => { ContentPopUp.IsOpen = true; txtToolTip.Text = "State 5 is not valid when State 1 is selected!!!\nActive MandatoryCriteriaList is: " + activeRowData.MandatoryCriteriaList; ContentPopUp.Placement = PlacementMode.Center; (sender as XamComboEditor).SelectedItem = ((sender as XamComboEditor).ItemsSource as IEnumerable<ComboData>).Where(i => i.State.Equals("State 1")).FirstOrDefault(); }), System.Windows.Threading.DispatcherPriority.SystemIdle, null); } if ((e.OldValue as ComboData).State.Equals("State 2") && ((e.NewValue as ComboData).State.Equals("State 4") || (e.NewValue as ComboData).State.Equals("State 5"))) { // MessageBox.Show("State 4 and State 5 is not valid when State 2 is selected!!!\nActive MandatoryCriteriaList is: " + activeRowData.MandatoryCriteriaList); Dispatcher.BeginInvoke(new Action(() => { ContentPopUp.Placement = PlacementMode.Center; ContentPopUp.IsOpen = true; txtToolTip.Text = "State 4 and State 5 is not valid when State 2 is selected!!!\nActive MandatoryCriteriaList is: " + activeRowData.MandatoryCriteriaList; // (sender as XamComboEditor).SelectedItem = ((sender as XamComboEditor).ItemsSource as IEnumerable<ComboData>).Where(i => i.State.Equals("State 2")).FirstOrDefault(); }), System.Windows.Threading.DispatcherPriority.SystemIdle, null); } } // (sender as XamComboEditor).SelectedItemChanged += XamComboEditor_SelectedItemChanged; }
I am just checking if you require any further assistance on the matter.
Using this dispatcher works fine for me in code behind.
But how I can handle when I am opening the popup in my ViewModel. Suppose I am binding the IsOpen property of popup and setting this property to true in my View not in code behind.
Thank you for your reply. I am very glad that the approach I have suggested was helpful for you. Please let me know if you need any further assistance on the matter.
Thanks for the help. This works for me.
Thanks
Arpita
Thank you for your reply. I am very glad that the approach I have suggested was helpful. I am using the SetCellValue method, since the Cell.Value property is read only and you can set the value of the cell, through the cell itself. This method is creating a CellValueObject which contains one dependency property and then creates a Binding between the property that corresponds to the current cell and the Value property of the CellValueObject, through the Data of the current row. After that, it sets the Value property of the CellValueObject, which triggers the Binding and this way the value of the property that corresponds to the cell is set, without interacting with the Data item of the current row.
Regarding the code that you have mentioned, in the CellExitingEditMode, I am de-attaching the handler, since each time the editor enters edit mode, a handler is attached to the Click event. If this code is commented, the hadnlers of the event will increase with one each time the Cell enters edit mode. This will case multiple execution of the the same function and when you enter ‘n’ times edit mode, for one cell and then click on the CheckBox, you will see that ‘n’ MessageBoxes are opened one after another.
Thsi is fine. Can you please explain this SetCellValue function and why you have used this line
(e.Editor
as CheckBox).Click -= new RoutedEventHandler
(MainWindow_Click);
in CellExitingEditMode event.