public class DummyObj
{
public int ID { get; set; }
public int Col1 { get; set; }
public int Col2 { get; set; }
public int Col3 { get; set; }
public int Col4 { get; set; }
public int Col5 { get; set; }
}

xmlns:bn="clr-namespace:BindingNavigator;assembly=BindingNavigator"<bn:BindingNavigator Grid.Row="0" Margin="2" Background="Wheat"
x:Name="navigator"
ItemsSource="{Binding People}"
AddNewItemCommand="{Binding AddNewPersonCommand}"
DeleteItemCommand="{Binding DeletePersonCommand}"
SaveCommand="{Binding SaveCommand}"/>|
PROBLEM If you have a GridViewCheckBox column to your gridview you need to click three times by default in order to change the value of the checkbox - the first two clicks will enter the edit mode and the last one will change the value. The following solutions will give you options to control the number of clicks needed to change the value of the checkbox column. SOLUTION
|
<Window x:Class="DynamicColumnSample.MainWindow" xmlns:local="clr-namespace:DynamicColumnSample" xmlns:my="clr-namespace:DynamicColumnSample.Objects" xmlns:dxb="http://schemas.devexpress.com/winfx/2008/xaml/bars" Title="MainWindow" xmlns:dx="http://schemas.devexpress.com/winfx/2008/xaml/core" xmlns:DynamicColumnSanple="clr-namespace:DynamicColumnSample" Width="525" Height="364"> <Window.DataContext> <local:ViewModel /> </Window.DataContext> <Window.Resources> <my:ColumnTemplateSelector x:Key="ColumnTemplateSelector" /> <DataTemplate x:Key="DefaultColumnTemplate"> <ContentControl> <dxg:GridColumn AllowEditing="False" my:ColumnBindingHelper.BindingPath="{Binding FieldName}" Header="{Binding Header}" /> </ContentControl> </DataTemplate> <DataTemplate x:Key="TextColumnTemplate"> <ContentControl> <dxg:GridColumn AllowEditing="True" my:ColumnBindingHelper.BindingPath="{Binding FieldName}" Header="{Binding Header}" > <dxg:GridColumn.EditSettings> <dxe:TextEditSettings Tag="{Binding Path=Tag}" ToolTip="{Binding Path=ToolTip}" /> </dxg:GridColumn.EditSettings> </dxg:GridColumn> </ContentControl> </DataTemplate> </Window.Resources> <Grid> <dx:PopupBase Name="hitInfoPopup" Placement="Mouse" PlacementTarget="{Binding ElementName=treeListStoreUnitSchedule}" Opened="hitInfoPopup_Opened"> <Grid Width="250" Height="250" Background="Beige"> <Border Padding="12,8,24,10"> <ItemsControl Name="hitIfoItemsControl"> <ItemsControl.ItemTemplate> <DataTemplate> <StackPanel Orientation="Horizontal" > <TextBlock Text="{Binding Name}"></TextBlock> <TextBlock Text="{Binding Text}"></TextBlock> </StackPanel> </DataTemplate> </ItemsControl.ItemTemplate> </ItemsControl> </Border> </Grid> </dx:PopupBase> <dxg:GridControl x:Name="treeListStoreUnitSchedule" Grid.Row="1" ColumnGeneratorTemplateSelector="{StaticResource ColumnTemplateSelector}" ColumnsSource="{Binding GridColumns}" ItemsSource="{Binding RegionObjects}"> <dxg:GridControl.Resources> <my:CustomChildrenSelector x:Key="childrenSelector" /> </dxg:GridControl.Resources> <dxg:GridControl.View> <dxg:TreeListView x:Name="view" ChildNodesSelector="{StaticResource childrenSelector}" TreeDerivationMode="ChildNodesSelector" local:TreeListExpandedNodesHelper.SynchIsExpanded="True" > <dxg:TreeListView.RowCellMenuCustomizations> <dxb:BarCheckItem Name="checkItem1" Content="Checked" IsChecked="True" dxb:BarItemLinkActionBase.ItemLinkIndex="0" /> <dxb:BarItemLinkSeparator dxb:BarItemLinkActionBase.ItemLinkIndex="1" /> </dxg:TreeListView.RowCellMenuCustomizations> <dxg:TreeListView.CellTemplate> <DataTemplate> <BorderBorderBrush="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type dxg:GridCellContentPresenter}}, Path=BorderBrush}"BorderThickness="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type dxg:GridCellContentPresenter}}, Path=BorderThickness}"> <dxe:TextEdit x:Name="PART_Editor"/> </Border> </DataTemplate> </dxg:TreeListView.CellTemplate> </dxg:TreeListView> </dxg:GridControl.View> </dxg:GridControl> <Button Command="{Binding Path=AddCommand}" Content="Button" Height="23" HorizontalAlignment="Left" Margin="321,0,0,0" Name="button1" VerticalAlignment="Top" Width="75" /> </Grid></Window>private void PopulateMonthList() { try { ObservableCollection<MonthInfo> tmpMonthInfo = new ObservableCollection<MonthInfo>(){ new MonthInfo(){MonthName="2011-01", MonthNumber=201101}, new MonthInfo(){MonthName="2011-02", MonthNumber=201102}, new MonthInfo(){MonthName="2011-03", MonthNumber=201103}, new MonthInfo(){MonthName="2011-04", MonthNumber=201104}, new MonthInfo(){MonthName="2011-05", MonthNumber=201105}, new MonthInfo(){MonthName="2011-06", MonthNumber=201106}, new MonthInfo(){MonthName="2011-07", MonthNumber=201107}, new MonthInfo(){MonthName="2011-08", MonthNumber=201108}, new MonthInfo(){MonthName="2011-09", MonthNumber=201109}, new MonthInfo(){MonthName="2011-10", MonthNumber=201110}, new MonthInfo(){MonthName="2011-11", MonthNumber=201111}, new MonthInfo(){MonthName="2011-12", MonthNumber=201112}, new MonthInfo(){MonthName="2012-01", MonthNumber=201201}, }; TextColumn txtColumn = null; for (int i = 0; i < 13; i++) { txtColumn = new TextColumn(); txtColumn.FieldName = "SalesInfoObject[" + i.ToString() + "].Quantity"; txtColumn.Header = tmpMonthInfo[i].MonthName.ToString(); txtColumn.Setting = SettingsType.Text; txtColumn.Tag = "SalesInfoObject[" + i.ToString() + "]"; txtColumn.ToolTip = "SalesInfoObject[" + i.ToString() + "]" + "].Brand"; _gridColumns.Add(txtColumn); } _gridColumns.Insert(0, new GridColumn() { Header = "Store Region", FieldName = "Name", Setting = SettingsType.Default }); _gridColumns.Insert(1, new GridColumn() { Header = "Store Quantity", FieldName = "Count", Setting = SettingsType.Default }); OnPropertyChanged("GridColumns"); } catch (Exception ex) { throw ex; }
<CollectionViewSource x:Key="categoriesViewSource" d:DesignSource="{d:DesignInstance Model:Category, CreateList=True}" />
<telerik:RadTreeView HorizontalAlignment="Stretch" IsEditable="True"
ItemsSource="{Binding}"
Name="CategoryTreeView"
VerticalAlignment="Stretch"
SelectionChanged="CategoryTreeView_OnSelectionChanged"
KeyUp="CategoryTreeView_KeyUp"
Edited="CategoryTreeView_Edited">
<telerik:RadTreeView.ItemEditTemplate>
<DataTemplate>
<TextBox Text="{Binding Name, Mode=TwoWay}"/>
</DataTemplate>
</telerik:RadTreeView.ItemEditTemplate>
<telerik:RadTreeView.ItemTemplate>
<HierarchicalDataTemplate ItemsSource="{Binding Subcategories}">
<TextBlock Text="{Binding Name}" />
</HierarchicalDataTemplate>
</telerik:RadTreeView.ItemTemplate>
</telerik:RadTreeView>
Category parent = CategoryTreeView.SelectedItem == nullEverything also works fine and child items are inserting to selected node. Works until I try to add a root node. When no selected item is available, this code won't work. New category adds to collection but never displays on tree. Can you please help me?
? null
: _context.Categories.FirstOrDefault(
c => c.CategoryID == ((Category) CategoryTreeView.SelectedItem).CategoryID);
Category newCategory = new Category
{
Name = "New category",
ParentCategory = parent,
ParentID = parent == null ? (Guid?) null : parent.CategoryID
};
_context.Categories.AddObject(newCategory);
