Hi,
in my xamGrid i have a templatecolumn with a checkbox in it and a textcolumn. The textcolumn should be editable the whole time until the checkbox is checked. If the checkbox is not checked the textcolumn should return to edit mode.
How can i achieve this?
Thanks in advance
I solved in on my own. Just changed the controls in the cells every time i check the checkbox.
<ig:ColumnLayout.Columns> <ig:TextColumn Key="AttributeModel.Attribute" HeaderText="{Binding ArticleAttributeList_XamGridTextColumn_Attribute_HeaderText, Source={StaticResource Localization}}" /> <ig:TextColumn Key="AttributeModel.Measure" HeaderText="{Binding ArticleAttributeList_XamGridTextColumn_Measure_HeaderText, Source={StaticResource Localization}}" /> <ig:TextColumn Key="AttributeModel.Value" HeaderText="{Binding ArticleAttributeList_XamGridTextColumn_Value_HeaderText, Source={StaticResource Localization}}" /> <ig:TemplateColumn Key="Status" HeaderText="{Binding ArticleAttributeList_XamGridTextColumn_Status_HeaderText, Source={StaticResource Localization}}"> <ig:TemplateColumn.ItemTemplate> <DataTemplate> <CheckBox IsChecked="{Binding Status}" Checked="Status_Checked" Unchecked="Status_Unchecked" /> </DataTemplate> </ig:TemplateColumn.ItemTemplate> </ig:TemplateColumn> </ig:ColumnLayout.Columns>
private void Status_Checked(object sender, RoutedEventArgs e) { if (articleList.ActiveCell == null) return; if (articleList.ActiveCell.Control == null) return; if (articleList.ActiveCell.Control.Content == null) return; if (articleList.ActiveCell.Control.Content as CheckBox != sender as CheckBox) return; if (articleList.ActiveCell.Row == null) return; if (articleList.ActiveCell.Row.Cells == null) return; if (articleList.ActiveCell.Row.Cells.Count < 4) return; TextBlock textBlock = new TextBlock(); Binding binding = new Binding("AttributeModel.Value"); textBlock.SetBinding(TextBlock.TextProperty, binding); articleList.ActiveCell.Row.Cells[2].Control.Content = textBlock; }
Like i said while in editing mode i can't do anything except editing the cell. But i would like to change other data AND hold the cell in editing mode until i check the box.
my shortened xaml
<ig:XamGrid ItemsSource="{Binding ArticleAttributeModels, UpdateSourceTrigger=Default}" AutoGenerateColumns="False" x:FieldModifier="private" Name="articleList" CellExitingEditMode="articleList_CellExitingEditMode"> <ig:XamGrid.Columns> <TextColumns ...> <ig:ColumnLayout Key="Attributes" AutoGenerateColumns="False"> <ig:ColumnLayout.Columns> <ig:TemplateColumn Key="AttributeModel.Attribute" > <ig:TemplateColumn.ItemTemplate> <DataTemplate> <TextBlock Text="{Binding AttributeModel.Attribute}" /> </DataTemplate> </ig:TemplateColumn.ItemTemplate> </ig:TemplateColumn> <ig:TemplateColumn Key="AttributeModel.Measure" > <ig:TemplateColumn.ItemTemplate> <DataTemplate> <TextBlock Text="{Binding AttributeModel.Measure}" /> </DataTemplate> </ig:TemplateColumn.ItemTemplate> </ig:TemplateColumn> <ig:TemplateColumn Key="AttributeModel.Value" > <ig:TemplateColumn.ItemTemplate> <DataTemplate> <TextBlock Text="{Binding AttributeModel.Value}" /> </DataTemplate> </ig:TemplateColumn.ItemTemplate> <ig:TemplateColumn.EditorTemplate> <DataTemplate> <Editors:XamComboEditor IsEditable="True" ItemsSource="{Binding SuggestedValues}" /> </DataTemplate> </ig:TemplateColumn.EditorTemplate> </ig:TemplateColumn> <ig:TemplateColumn Key="Status" > <ig:TemplateColumn.ItemTemplate> <DataTemplate> <CheckBox IsChecked="{Binding Status}" Checked="Status_Checked" Unchecked="Status_Unchecked"/> </DataTemplate> </ig:TemplateColumn.ItemTemplate> <ig:TemplateColumn.EditorTemplate> <DataTemplate> <StackPanel Orientation="Horizontal"> <TextBlock Text="Score:" /> <TextBlock Text="{Binding Score}" Margin="3,0" /> <CheckBox IsChecked="{Binding Status}" Checked="Status_Checked" Unchecked="Status_Unchecked"/> </StackPanel> </DataTemplate> </ig:TemplateColumn.EditorTemplate> </ig:TemplateColumn> </ig:ColumnLayout.Columns> <ig:ColumnLayout.EditingSettings> <ig:EditingSettingsOverride AllowEditing="Cell" /> </ig:ColumnLayout.EditingSettings>
my shortened c# code
private void Status_Checked(object sender, RoutedEventArgs e) { articleList.ExitEditMode(true); } private void Status_Unchecked(object sender, RoutedEventArgs e) { articleList.EnterEditMode(articleList.ActiveCell.Row.Cells[2]); } private void articleList_CellExitingEditMode(object sender, ExitEditingCellEventArgs e) { if (e.Cell.Column.Key == "AttributeModel.Value") { e.Cancel = (bool)e.Cell.Row.Cells[3].Value; } }
In a perfect world my xamgrid should change the look of the cell with the key "Status" and should make the cell with the key "Value" editable / not editable if the user presses the checkbox.
I'm not exactly sure what you're trying to achieve. If I understand you correctly, you might try checking the value of the checkbox in CellExitingEditMode event and cancel the operation if the checkbox is not checked. Assuming your TemplateColumn is bound to a boolean property in your data object, the code should look something like this:
private void igGrid_CellExitingEditMode(object sender, ExitEditingCellEventArgs e)
{
if (e.Cell.Column.Key == "MyTextColumnKey")
e.Cancel = !((MyDataObject)e.Cell.Row.Data).MyBoolProperty;
}
Hope that helps,
I need help asap!
During the edit mode it isn't possible to edit other columns. I need a solution where i can edit all values until their checkbox is checked.