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 replies. Regarding your first reply, the method that you have referred is used for finding elements on the visual tree of the application. You can also use the Utilities’ GetDescendentFromType method in order to find the TextBlock in the CellControlAttached event.
I have investigated the issue that you have described in your second reply and it seems that it is caused by the Margin property of the TextBlock in the MergedContentControl. In order to avoid this appearance you can set the margin to 0 and also set the Margin property of the ContentPresenter in the CellControl template to 10 as follows:
<Style TargetType="ig:CellControl"> .............. <Border BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}" x:Name="Root"/> <Rectangle x:Name="AltMouseOver" Margin="{TemplateBinding BorderThickness}"/> <Border x:Name="ActiveSelected" BorderBrush="{StaticResource CellItemSelectedBorderBrush}" ></Border> <ContentPresenter VerticalAlignment="{TemplateBinding VerticalContentAlignment}" HorizontalAlignment="Center" Margin="10"/> ................ </Style> <Style TargetType="igPrim:MergedContentControl"> <Setter Property="Background" Value="{StaticResource CellItemNormalBackgroundBrush}"/> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="igPrim:MergedContentControl"> <Border x:Name="Bd" Background="{TemplateBinding Background}" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}"> <Grid> <TextBlock VerticalAlignment="Center" HorizontalAlignment="Center" TextWrapping="Wrap" TextAlignment="Center" Text="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=Content.Text}" Margin="0"/> </Grid> </Border> </ControlTemplate> </Setter.Value> </Setter> </Style>
I am just checking if you require any further assistance on the matter.
Hi Krasimir,
Once you have modified the sample application in order to show an error message when an invalid item is selected. To do that you have used different approach which uses a converter to the binding of the Value property of the editor. When an item is selected form the combo’s drop down, in the convert method you are comparing the value of the currently selected item and the actual value of the editor and you are showing an error message.
In this The error message pops up as soon as wrong value is selected but it returns to its last or old value only when I click somewhere . Can you help with this Please ?
I am facing one more issue in converter I cannot access the active row of grid which I was doing in selection item changed event . here is the code .
private void XamComboEditor_SelectedItemChanged(object sender, RoutedPropertyChangedEventArgs<object> e)
{
try
if (e.NewValue != null
)
RecipeStateDetails d = (RecipeStateDetails
)(ManageRecipeStateGrid.ActiveCell.Row.Data);
//if ((e.NewValue as ComboData).State.Equals("State 4"))
if (d.PreviousRecipeState.Equals("Ready") && (d.CurrentRecipeState.Equals("Not Ready") || d.CurrentRecipeState.Equals("Bad")) && d.IsActivated.Equals("Y"
))
(sender
as XamComboEditor).ValueConstraint.Enumeration = new List<string> { "Ready"
};
as XamComboEditor).Tag = "Recipe " + d.MandatoryCriteriaList + " is activated so you cannot change to Not Ready or Bad state"
;
}
//if ((e.NewValue as ComboData).State.Equals("State 2"))
if (d.PreviousRecipeState.Equals("Bad") && d.CurrentRecipeState.Equals("Ready"
as XamComboEditor).ValueConstraint.Enumeration = new List<string> { "Not Ready", "Bad"
as XamComboEditor).Tag = "From Bad state it cab be changed only to Not Ready state for Recipe "
+ d.MandatoryCriteriaList;
catch (Exception
ex)
ATRMSLogger.Instrumentation.Error("Error in XamComboEditor_SelectedItemChanged: "
+ ex.Message);
Intel.ATTD.ThinWire.ControlsLibrary.
WPFMessageBox._bErrorMsg = true
WPFMessageBox
.Show(ex.Message);
In converter approach I can compare lastvalue and present value but I can not do comparison for other fiels in a row. example d.IsActivated.Equals("Y") something like this becoz we cannot access the active row here as we use to do in SelectionItemChanged event.
Thanks
Arpita
Can you please help me out with my query stated above ?
Can you please help me out ?
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.
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.