Hello, I implemented a dialog in which the user has the opportunity to add a new row in a XamGrid. He can do this over pressing on "F2" or "Enter" . For me, is that not user friendly.
I want to make it possible for the user to add a new row on clicking the lefty "plus"-icon.
Is that possible? And if so, how? Can I maybe change the style so that the "plus"-icon is a button? Thanks in advance! Regards, Djumana
Great work!
THANK YOU!
Hi,
If the collection that you set as ItemsSource implements INotifyCollectionChanged (for example: ObservableCollection<T>) it is as simple as adding a new item to the collection.
If you want to add the item through the XamGrid, you can use XamGrid.Rows.CreateItem(newItemObj) to create a row and then add the row to the XamGrid.Rows collection.
Regards
thank you very much!
How can I programmatically add a new row?
Bye,
Djumana
You can find few very useful articles in our Desingers Guide. The part that you have to customize is AddNewRowSelectorCellControl. You then have to set the new Style to xamGrid.AddNewRowSettings.RowSelectorStyle.
The best way to attach a custom behaviour when the cell is clicked is to create a custom command. You can use the snippet below as a starting point:
public class MyCustomRowCommand : RowCommandBase { protected override void ExecuteCommand(Row row) { MessageBox.Show("Clicked"); } } public class MyCustomCommandSource : CommandSource { protected override System.Windows.Input.ICommand ResolveCommand() { return new MyCustomRowCommand(); } }
... <LinearGradientBrush x:Key="HeaderCellGlyphBrush" StartPoint="0,0" EndPoint="0,1"> <LinearGradientBrush.GradientStops> <GradientStopCollection> <GradientStop Offset="0" Color="#FFa3aeb9" /> <GradientStop Offset="0.37" Color="#FF8399a9" /> <GradientStop Offset="0.370" Color="#FF718597" /> <GradientStop Offset="1" Color="#FF617583" /> </GradientStopCollection> </LinearGradientBrush.GradientStops> </LinearGradientBrush> <Style x:Key="Style1" TargetType="igPrim:AddNewRowSelectorCellControl"> <Setter Property="Background" Value="Red" /> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="igPrim:AddNewRowSelectorCellControl"> <Grid> <Border x:Name="border" IsHitTestVisible="False" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}" /> <Grid> <ig:Commanding.Commands> <local:MyCustomCommandSource EventName="MouseLeftButtonDown"/> </ig:Commanding.Commands> <Path Fill="#ffffff" Stretch="Fill" Stroke="{StaticResource HeaderCellGlyphBrush}" StrokeThickness="1" Data="M3.5,0.5 L6.5,0.5 L6.5,3.5 L9.5,3.5 L9.5,6.5 L6.5,6.5 L6.5,9.5 L3.5,9.5 L3.5,6.5 L0.5,6.5 L0.5,3.5 L3.5,3.5 z" Width="10" Height="10" /> </Grid> </Grid> </ControlTemplate> </Setter.Value> </Setter> </Style> ... <ig:XamGrid x:Name="XGrid" ItemsSource="{Binding Data}"> <ig:XamGrid.AddNewRowSettings> <ig:AddNewRowSettings RowSelectorStyle="{StaticResource Style1}" AllowAddNewRow="Top" /> </ig:XamGrid.AddNewRowSettings> ...
Hope this helps