I have a RadGridView, that groups its contents.
I have a Button on the group header
When I click on the button (btnSave) I would like to get access to the group to read the group key.
What can I put in the Click of btnSave to accomplish this?
<telerik:RadGridView x:Name="grdNotams" Grid.Row="1" AutoGenerateColumns="False" RowIndicatorVisibility="Collapsed" ShowGroupPanel="False">
<telerik:RadGridView.Columns>
<telerik:GridViewDataColumn UniqueName="colNewStatus" DataMemberBinding="{Binding NewStatus}" Header="New Status" IsFilterable="False" IsSortable="False">
<telerik:GridViewDataColumn.CellTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<telerik:RadRadioButton Content="C" Width="30" IsChecked="{Binding NewStatus, Mode=TwoWay, Converter={StaticResource StringToBooleanConverter},ConverterParameter=C}" GroupName="{Binding RadioButtonName}"/>
<telerik:RadRadioButton Content="M" Width="30" Margin="5,0,0,0" IsChecked="{Binding NewStatus, Mode=TwoWay, Converter={StaticResource StringToBooleanConverter},ConverterParameter=M}" GroupName="{Binding RadioButtonName}"/>
<telerik:RadRadioButton Content="I" Width="30" Margin="5,0,0,0" IsChecked="{Binding NewStatus, Mode=TwoWay, Converter={StaticResource StringToBooleanConverter},ConverterParameter=I}" GroupName="{Binding RadioButtonName}"/>
</StackPanel>
</DataTemplate>
</telerik:GridViewDataColumn.CellTemplate>
</telerik:GridViewDataColumn>
<telerik:GridViewDataColumn Header="Status" UniqueName="colStatus" DataMemberBinding="{Binding Model.Status, Converter={StaticResource StatusConverter}}" HeaderTextAlignment="Center" TextAlignment="Center" IsFilterable="False" IsSortable="False"/>
<telerik:GridViewDataColumn Header="Trip #" UniqueName="colTripNumber" DataMemberBinding="{Binding Model.TripNumber}" HeaderTextAlignment="Center" TextAlignment="Center" IsFilterable="False" IsSortable="False"/>
<telerik:GridViewDataColumn Header="Date" UniqueName="colDate" DataMemberBinding="{Binding Model.DepartureTime}" DataFormatString="d" HeaderTextAlignment="Center" TextAlignment="Center" IsFilterable="False" IsSortable="False"/>
</telerik:RadGridView.Columns>
<telerik:RadGridView.GroupHeaderTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<telerik:RadButton x:Name="btnSave" Click="btnSave_Click">
<StackPanel Orientation="Vertical">
<Image Source="../images/save.jpg" Height="30" Width="30" HorizontalAlignment="Center"/>
<TextBlock TextAlignment="Center" TextWrapping="Wrap">Update</TextBlock>
</StackPanel>
</telerik:RadButton>
<TextBlock Text="{Binding Group.Key}" FontSize="14" FontWeight="Bold" FontStyle="{Binding EarliestNotamDepartureTime, Converter={StaticResource DateTimeToItalicsConverter}}" TextWrapping="Wrap" VerticalAlignment="Center" Padding="5"/>
</StackPanel>
</DataTemplate>
</telerik:RadGridView.GroupHeaderTemplate>
<telerik:RadGridView.GroupDescriptors>
<telerik:GroupDescriptor Member="NotamGroup" >
</telerik:GroupDescriptor>
<telerik:GroupDescriptor Member="Model.NotamText">
</telerik:GroupDescriptor>
</telerik:RadGridView.GroupDescriptors>
</telerik:RadGridView>
Figured it out.
The DataContext has the information I needed in the form of the GroupViewModel class.
Code
private void btnSave_Click(object sender, RoutedEventArgs e)
{
GroupViewModel vm = ((RadButton)sender).DataContext as GroupViewModel;
}
Related
There is a textbox in the gridviewColumn And a ComboBox in the other column In need to set the TextBox read only true and readOnly False On the section On COmboBox.
<telerik:GridViewDataColumn x:Name="requstamount" Header="Request Amount" Width="200">
<telerik:GridViewColumn.CellTemplate >
<DataTemplate>
<TextBox IsEnabled="{Binding IsTextBoxEnabled, StringFormat=c, UpdateSourceTrigger=PropertyChanged, Mode=TwoWay}"
Name="txtPaymentAMNT"
Text="{Binding PaymentAmount, StringFormat=c, UpdateSourceTrigger=PropertyChanged}"
Background="Transparent"
LostFocus="text_LostFocus"
BorderBrush="LightGray"
BorderThickness="0,0,0,3"
Width="141"
Margin="-5,0,0,0" />
</DataTemplate>
</telerik:GridViewColumn.CellTemplate>
</telerik:GridViewDataColumn>
<telerik:GridViewDataColumn Header="Request Type" Width="150">
<telerik:GridViewColumn.CellTemplate >
<DataTemplate>
<telerik:RadComboBox x:Name="cboType"
Background="Transparent"
HorizontalAlignment="Left"
BorderBrush="blue"
BorderThickness="0,0,0,1"
Margin="-5,0,0,0"
telerik:StyleManager.Theme="Office2019"
Width="100"
Height="25"
SelectedIndex="{Binding Path=Reqsttype, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
SelectionChanged="cmbType_SelectionChanged"
SelectedValuePath="{Binding OrderNo}">
<telerik:RadComboBoxItem Name="Pre_Auth" IsSelected="True">
Pre-Auth
</telerik:RadComboBoxItem>
<telerik:RadComboBoxItem Name="Deposit">
Deposit
</telerik:RadComboBoxItem>
</telerik:RadComboBox>
</DataTemplate>
</telerik:GridViewColumn.CellTemplate>
</telerik:GridViewDataColumn>
I'm trying to put a ComboBox, a checkbox and a few textboxes inside a treeview in WPF.
Following is the basic structure of the treeview requirement
-Parent
--Label Textbox
--Label Textbox
--Label Textbox
--Label Combo box
--Label Check box
--Payload
---Label
----Label Textbox
----Label Combobox
----Label Textbox
Following is the xaml code
<TreeView x:Name="BTreeView" Grid.Column="1" Grid.Row="1" Margin="1,10,0,10" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" ItemsSource="{Binding TreeViewListings}" >
<TreeView.Resources>
<HierarchicalDataTemplate DataType="{x:Type viewmodel:TreeViewBViewModel}" ItemsSource="{Binding Positions}" >
<TextBlock Text="Level1"/>
<HierarchicalDataTemplate.ItemTemplate>
<HierarchicalDataTemplate ItemsSource="{Binding PayLoadList}" DataType="{x:Type viewmodel:Position}">
<StackPanel>
<StackPanel Orientation="Horizontal">
<TextBlock Text="Text 1" />
<TextBox Text="{Binding Path=Text1, UpdateSourceTrigger=PropertyChanged}" Width="200" Margin="10,0,0,0" BorderThickness="0" HorizontalAlignment="Left"/>
</StackPanel>
<StackPanel Orientation="Horizontal">
<TextBlock Text="Text 2" />
<TextBox Text="{Binding Path=Text1, UpdateSourceTrigger=PropertyChanged}" Width="200" Margin="10,0,0,0" BorderThickness="0" HorizontalAlignment="Left"/>
</StackPanel>
<StackPanel Orientation="Horizontal">
<TextBlock Text="Text 3"/>
<ComboBox Width="100" Height="18" Margin="10,0,0,0" VerticalAlignment="Top" HorizontalAlignment="Left" FontSize="10" IsEditable="True" IsReadOnly="True" BorderThickness="0">
<ComboBoxItem IsSelected="True">Item 1</ComboBoxItem>
<ComboBoxItem>Item 2</ComboBoxItem>
<ComboBoxItem>Item 3</ComboBoxItem>
<ComboBoxItem>Item 4</ComboBoxItem>
<ComboBoxItem>Item 5</ComboBoxItem>
</ComboBox>
</StackPanel>
<StackPanel Orientation="Horizontal">
<CheckBox Canvas.Left="10" Canvas.Top="10" Content="Active" IsChecked="False"/>
</StackPanel>
<TextBlock Text="{Binding PayLoadText}"/>
</StackPanel>
<HierarchicalDataTemplate.ItemTemplate>
<HierarchicalDataTemplate ItemsSource="{Binding PayLoadData}" DataType="{x:Type viewmodel:Payload}">
<Label Content="{Binding FieldName}"/>
<HierarchicalDataTemplate.ItemTemplate>
<DataTemplate DataType="{x:Type viewmodel:PayloadData}">
<StackPanel>
<StackPanel Orientation="Horizontal">
<TextBlock Text="Text 4" />
<TextBox Text="{Binding Path=Text4, UpdateSourceTrigger=PropertyChanged}" Width="200" Margin="10,0,0,0" BorderThickness="0" HorizontalAlignment="Left"/>
</StackPanel>
<StackPanel Orientation="Horizontal">
<TextBlock Text="{Binding Data}" />
<TextBox Text="{Binding Path=DataFieldValue, UpdateSourceTrigger=PropertyChanged}" Width="200" BorderThickness="0" HorizontalAlignment="Left"/>
</StackPanel>
<StackPanel Orientation="Horizontal">
<TextBlock Text="Operation" />
<ComboBox Width="100" Height="18" Margin="10,0,0,0" VerticalAlignment="Top" HorizontalAlignment="Left" FontSize="10" IsEditable="True" IsReadOnly="True" BorderThickness="0">
<ComboBoxItem>Item 1</ComboBoxItem>
<ComboBoxItem>Item 2</ComboBoxItem>
<ComboBoxItem>Item 3</ComboBoxItem>
<ComboBoxItem>Item 4</ComboBoxItem>
</ComboBox>
</StackPanel>
</StackPanel>
</DataTemplate>
</HierarchicalDataTemplate.ItemTemplate>
</HierarchicalDataTemplate>
</HierarchicalDataTemplate.ItemTemplate>
</HierarchicalDataTemplate>
</HierarchicalDataTemplate.ItemTemplate>
</HierarchicalDataTemplate>
</TreeView.Resources>
</TreeView>
I am using MVVM architectural pattern to achieve this goal. The problem that I am facing is with the arrow head of second level node. It is not aligned at the right position. The arrowhead gets automatically aligned to "Text3" combo box instead of "Payload" node. Following is the image of my tree view
I do not know if there is any other approach to include Combo box, check box, text boxes inside a treeview using MVVM approach. Would appreciate if you let me know your approach of designing this treeview
I have the following memory issue when sorting, filtering, grouping, pagging...:
I open the task manager for monitoring my app's memory, after load all data (like 500 records with 90 columns) the app's memory was like 150mb, then every time I repeat an action (I tried with reordering with any column) the memory increase, increase, increase and NEVER RELEASE
I tried the same test case with examples, and after load some memory the GC free the unused one.
Plesae helps, I will apreciate any tips.
Code
<telerik:RadGridView Name="dataGrid" Margin="4" Grid.Row="3" ItemsSource="{Binding Items}" IsReadOnly="True" SelectionMode="Extended" AlternationCount="2" AlternateRowBackground="LightGray" FrozenColumnCount="{Binding FrozenColumnIndex}" AutoGenerateColumns="False" RowIndicatorVisibility="Collapsed" view:GridViewHeaderMenu.IsEnabled="True" SelectedItem="{Binding SelectedItem, Mode=TwoWay}">
<telerik:RadGridView.Columns>
<view:NumberColumn Header="#" Width="50" DataPager="{Binding ElementName=radDataPager1}" />
<telerik:GridViewDataColumn Header="Col1" HeaderTextAlignment="Center" DataType="{x:Type System:String}" DataMemberBinding="{Binding Value1}" view:GridColumnToolTip.TextTooltip="{Binding DataContext.ColumnsDescription.Value1ColumnTooltip, ElementName=userControl}"/>
<telerik:GridViewDataColumn Header="Col2" HeaderTextAlignment="Center" DataType="{x:Type System:Int32}" DataMemberBinding="{Binding Value2}" view:GridColumnToolTip.TextTooltip="{Binding DataContext.ColumnsDescription.Value2ColumnTooltip, ElementName=userControl}"/>
<telerik:GridViewDataColumn Header="Col3" HeaderTextAlignment="Center" DataType="{x:Type System:Double}" DataMemberBinding="{Binding Value3}" DataFormatString="N3" view:GridColumnToolTip.TextTooltip="{Binding DataContext.ColumnsDescription.Value3ColumnTooltip, ElementName=userControl}"/>
<telerik:GridViewDataColumn Header="Col Hide/Show Binding" HeaderTextAlignment="Center" DataType="{x:Type System:String}" DataMemberBinding="{Binding Value4}" IsVisible="{Binding IsIndividual}" view:GridColumnToolTip.TextTooltip="{Binding DataContext.ColumnsDescription.Value4ColumnTooltip, ElementName=userControl}"/>
<!--other 90 columns-->
</telerik:RadGridView.Columns>
</telerik:RadGridView>
<StackPanel Orientation="Horizontal" Grid.Row="4" HorizontalAlignment="Left" Margin="4,0,0,0" VerticalAlignment="Center">
<telerik:RadDataPager x:Name="radDataPager1" PageSize="20" DisplayMode="All" Source="{Binding Items, ElementName=dataGrid}"
IsTotalItemCountFixed="True" HorizontalAlignment="Center" VerticalAlignment="Center"/>
<TextBlock TextWrapping="Wrap" Margin="8,0,0,0" HorizontalAlignment="Center" VerticalAlignment="Center" FontSize="10.667"><Run Text="Ta"/><Run Language="es-es" Text="maño de página:"/></TextBlock>
<telerik:RadNumericUpDown NumberDecimalDigits="0" Value="{Binding PageSize, ElementName=radDataPager1, Mode=TwoWay}" Minimum="1" VerticalAlignment="Center" HorizontalAlignment="Center" Margin="4,0,0,0"/>
</StackPanel>
I want to show a product list with a header like a DataGrid. But I don't know how to show heading in the listbox.
<ListBox ItemsSource="{Binding CustomSalesProducts, Mode=TwoWay}" HorizontalContentAlignment="Stretch" VerticalContentAlignment="Stretch" Template="{DynamicResource ListBox}" Style="{DynamicResource ListBoxStyle1}" BorderBrush="{DynamicResource BorderBrush}" Foreground="{DynamicResource ForegroundBrush}" FontFamily="Palatino Linotype" FontSize="13.333" ItemContainerStyle="{DynamicResource ListBoxItemStyle}" SelectedValue="{Binding CurrentCustomSale, Mode=TwoWay}">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<VirtualizingStackPanel CanHorizontallyScroll="True" CanVerticallyScroll="True" Orientation="Vertical"/>
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemTemplate>
<DataTemplate>
<StackPanel>
<StackPanel Orientation="Horizontal">
<TextBox Text="{Binding ProductName, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" Margin="{StaticResource Margin4}" Style="{DynamicResource MiniTextBoxStyle}" ToolTip="Quantity" KeyUp="TextBox_KeyUp"/>
<TextBox Text="{Binding OrderQty, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" Margin="{StaticResource Margin4}" Style="{DynamicResource MiniTextBoxStyle}" ToolTip="Quantity" KeyUp="TextBox_KeyUp">
</TextBox>
<TextBox Text="{Binding UnitSalePrice, Mode=TwoWay}" Style="{DynamicResource MiniTextBoxStyle}" Margin="{StaticResource Margin4}" ToolTip="Price" IsReadOnly="True" />
<TextBox Text="{Binding MainDiscount, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" Margin="{StaticResource Margin4}" Style="{DynamicResource MiniTextBoxStyle}" ToolTip="Discount" KeyUp="TextBox_KeyUp"/>
<TextBox Text="{Binding Discount, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" Margin="{StaticResource Margin4}" IsReadOnly="True" Style="{DynamicResource MiniTextBoxStyle}" ToolTip="Line Discount" KeyUp="TextBox_KeyUp"/>
<TextBox Text="{Binding TaxAmount, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" Margin="{StaticResource Margin4}" Style="{DynamicResource MiniTextBoxStyle}" ToolTip="Tax Amount" IsReadOnly="True" />
<TextBox Text="{Binding LineTotal, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" Margin="{StaticResource Margin4}" Style="{DynamicResource MiniTextBoxStyle}" ToolTip="Total" IsReadOnly="True" />
</StackPanel>
</StackPanel>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ListBox>
I want this kind of output
--------------------------------------
ID Name Price Discount
1 xxxx 1245 8
2 xxxxxxxx 4354 9
..... and so on..
I think what you really whant is a ListView with a GridView view.
<ListView ItemsSource="{Binding Source=
{StaticResource EmployeeInfoDataSource}}">
<ListView.View>
<GridView AllowsColumnReorder="true"
ColumnHeaderToolTip="Employee Information">
<GridViewColumn DisplayMemberBinding=
"{Binding Path=FirstName}"
Header="First Name" Width="100"/>
<GridViewColumn DisplayMemberBinding=
"{Binding Path=EmployeeNumber}"
Header="Employee No." Width="100"/>
</GridView>
</ListView.View>
</ListView>
So I build a nice nested datagrid that look something like this:
<dg:DataGrid x:Name="mainGrid"
AutoGenerateColumns="False"
CanUserAddRows="False"
AreRowDetailsFrozen="True"
CanUserReorderColumns="False"
CanUserResizeColumns="True"
CanUserResizeRows="False"
SelectionUnit="FullRow"
RowDetailsVisibilityMode="VisibleWhenSelected">
<dg:DataGrid.Columns>
<dg:DataGridTemplateColumn CanUserResize="False" CanUserSort="False" Width="36" IsReadOnly="False">
<dg:DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<Button Content="+" Width="28" Height="28" />
</DataTemplate>
</dg:DataGridTemplateColumn.CellTemplate>
</dg:DataGridTemplateColumn>
<dg:DataGridTemplateColumn>
<dg:DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<Grid>
<CheckBox IsChecked="{Binding IsSelected, Mode=TwoWay}"/>
</Grid>
</DataTemplate>
</dg:DataGridTemplateColumn.CellTemplate>
</dg:DataGridTemplateColumn>
<dg:DataGridTemplateColumn Header="Name" IsReadOnly="True" Width="582">
<dg:DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<TextBlock Margin="5" VerticalAlignment="Center" Text="{Binding Name, Mode=TwoWay, UpdateSourceTrigger=Default}" />
</DataTemplate>
</dg:DataGridTemplateColumn.CellTemplate>
</dg:DataGridTemplateColumn>
<dg:DataGridTemplateColumn Header="Status" IsReadOnly="True" Width="150">
<dg:DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<TextBlock Margin="5" VerticalAlignment="Center" Text="{Binding Status, Mode=TwoWay, UpdateSourceTrigger=Default}" />
</DataTemplate>
</dg:DataGridTemplateColumn.CellTemplate>
</dg:DataGridTemplateColumn>
<dg:DataGridCheckBoxColumn Binding="{Binding IsSelected}"/>
</dg:DataGrid.Columns>
<dg:DataGrid.RowDetailsTemplate>
<DataTemplate>
<dg:DataGrid x:Name="scondaryDatagrid" Margin="29,0,0,0"
AutoGenerateColumns="False"
CanUserAddRows="False"
AreRowDetailsFrozen="True"
CanUserReorderColumns="False"
CanUserResizeColumns="True"
CanUserResizeRows="False"
SelectionUnit="Cell"
RowDetailsVisibilityMode="VisibleWhenSelected"
ItemsSource="{Binding Grades, Mode=TwoWay}">
<dg:DataGrid.Columns>
<dg:DataGridTemplateColumn CanUserResize="False" CanUserSort="False" Width="32" IsReadOnly="True">
<dg:DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<Button Content="+" Width="28" Height="28" />
</DataTemplate>
</dg:DataGridTemplateColumn.CellTemplate>
</dg:DataGridTemplateColumn>
<dg:DataGridTemplateColumn CanUserResize="False" CanUserSort="False" Width="32" IsReadOnly="True">
<dg:DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<CheckBox IsChecked="{Binding IsSelected, Mode=TwoWay}" VerticalAlignment="Center" HorizontalAlignment="Center" HorizontalContentAlignment="Center" />
</DataTemplate>
</dg:DataGridTemplateColumn.CellTemplate>
</dg:DataGridTemplateColumn>
<dg:DataGridTemplateColumn Header="Name" IsReadOnly="True" Width="550">
<dg:DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<TextBlock Margin="5" Text="{Binding Name, Mode=TwoWay}" VerticalAlignment="Center" />
</DataTemplate>
</dg:DataGridTemplateColumn.CellTemplate>
</dg:DataGridTemplateColumn>
</dg:DataGrid.Columns>
<dg:DataGrid.RowDetailsTemplate>
<DataTemplate>
<dg:DataGrid Margin="25,0,0,0"
AutoGenerateColumns="False"
CanUserAddRows="False"
AreRowDetailsFrozen="True"
CanUserReorderColumns="False"
CanUserResizeColumns="True"
CanUserResizeRows="False"
SelectionUnit="Cell"
ItemsSource="{Binding Notes, Mode=TwoWay}">
<dg:DataGrid.Columns>
<dg:DataGridTemplateColumn CanUserResize="False" CanUserSort="False" Width="32" IsReadOnly="True">
<dg:DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<CheckBox IsChecked="{Binding IsSelected, Mode=TwoWay}" VerticalAlignment="Center" HorizontalAlignment="Center" />
</DataTemplate>
</dg:DataGridTemplateColumn.CellTemplate>
</dg:DataGridTemplateColumn>
<dg:DataGridTemplateColumn Header="Note" IsReadOnly="True" Width="550">
<dg:DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<TextBlock Margin="5" Text="{Binding Note, Mode=TwoWay}" VerticalAlignment="Center" />
</DataTemplate>
</dg:DataGridTemplateColumn.CellTemplate>
</dg:DataGridTemplateColumn>
</dg:DataGrid.Columns>
</dg:DataGrid>
</DataTemplate>
</dg:DataGrid.RowDetailsTemplate>
</dg:DataGrid>
</DataTemplate>
</dg:DataGrid.RowDetailsTemplate>
</dg:DataGrid>
Due to the RowDetailsVisibilityMode property when it is set to VisibleWhenSelected, the Node DataGridDetailsPresenter for the rows have 0 children. When the property is set to Visible I can see the DataGridDetailsPresenter children.
How can I force the inclusion of all the nodes in the Visual tree for when the RowDetailsVisibilityMode property is VisibleWhenSelected?
Any input is greatly appreciated.
What are you trying to accomplish?
Unless the the RowDetails are visible they would not be in the Visual Tree unless could force their creation by setting the RowDetailsVisibilityMode to Visible but setting the RowDetails DataGrid visibility to Collapsed. This may not work. I don't know if the DataGrid would be in the Visual Tree if set to Collapsed in 3.5.