wpfdatagrid

How to handle whitespace in DataTrigger binding for WPF DataGrid?

为君一笑 提交于 2020-01-06 02:36:45
问题 I am using autogenerating datagrid and binding it to a DataTable.This DataTable has columns with whitespaces like 'Last Value'. Now I need to add a datatrigger to apply some style as shown below: <DataGrid.Resources> <Style x:Key="DgStyle" TargetType="{x:Type TextBlock}"> <Setter Property="TextAlignment" Value="Right"/> <Style.Triggers> <DataTrigger Binding="{Binding Last Value, Converter= {StaticResource DecimalToBoolConverter}}" Value="True"> <Setter Property="Foreground" Value="Red" /> <

DataGrid Setting the size of columns in code behind when the columns are auto generated

半腔热情 提交于 2020-01-05 02:11:17
问题 I am auto generating my columns <DataGrid Grid.Row="0" AutoGenerateColumns="True" VerticalAlignment="Stretch" HorizontalAlignment="Stretch" Name="dataGrid1" ItemsSource="{Binding Customers}" /> Now I want to set the size of each column in the code behind , to do something like this <DataGrid> <DataGrid.Columns> <DataGridTextColumn Width="Auto" /> <DataGridTextColumn Width="Auto" /> <DataGridTextColumn Width="*" /> </DataGrid.Columns> </DataGrid> I just want to attach to each column "Auto" ,

Coloring WPF DataGridRows one by one

泪湿孤枕 提交于 2020-01-04 11:40:07
问题 I'm making a WPF program which is able to color the rows in a DataGrid one by one in red using the for loop and I've encountered something weird. If the DataGrid has more than 40 rows of data from a database table, it doesn't color all the rows. Here's the code I'm using. private void Red_Click(object sender, RoutedEventArgs e) { for (int i = 0; i < dataGrid1.Items.Count; i++) { DataGridRow row = (DataGridRow)dataGrid1.ItemContainerGenerator.ContainerFromIndex(i); if (row != null) { row

Coloring WPF DataGridRows one by one

左心房为你撑大大i 提交于 2020-01-04 11:39:29
问题 I'm making a WPF program which is able to color the rows in a DataGrid one by one in red using the for loop and I've encountered something weird. If the DataGrid has more than 40 rows of data from a database table, it doesn't color all the rows. Here's the code I'm using. private void Red_Click(object sender, RoutedEventArgs e) { for (int i = 0; i < dataGrid1.Items.Count; i++) { DataGridRow row = (DataGridRow)dataGrid1.ItemContainerGenerator.ContainerFromIndex(i); if (row != null) { row

How to remove wpf grid sort arrow after clearing sort descriptions

一个人想着一个人 提交于 2020-01-03 13:20:11
问题 I click on a grid header to sort a column and then click a "Reset" button to clear the sort descriptions through its collection view. But the sort arrow icon still persists in the header. How to remove it? 回答1: simple solution i can think of is foreach (DataGridColumn column in DataGridView.Columns) { column.SortDirection = null; } 回答2: I came across this question whilst trying to work out how to clear the sort from the grid completely. Thanks to [krishnaaditya] for the answering how to clear

Wpf DataGrid SelectedItem loses binding after cell edit

不问归期 提交于 2020-01-03 04:22:06
问题 I have a DataGrid bound to a collection of items (Rules). If I edit one of these items manually in the DataGrid, it seems like the SelectedItem binding on the grid stops working ( RuleListViewModelPropertyChanged in the controller is never called again). But only if I actually change the value of the item in the cell, otherwise SelectedItem keeps working like it should. I have stripped the code of some irrelevant things, so this is basically what I have. First, I have the following DataGrid :

select all checkbox in header of datagrid and its binding in wpf mvvm

只谈情不闲聊 提交于 2020-01-03 03:30:30
问题 I am working on wpf (mvvm architecture). A am using datagrid to list the checkboxes and a SELECT ALL checkbox in the header on click of which I want all the checkboxes to be checked and vice-versa.Please help. I am giving my code description here... This is the View.xaml <DataGridCheckBoxColumn Binding="{Binding IsSelected}" Width="50" > <DataGridCheckBoxColumn.HeaderTemplate> <DataTemplate x:Name="dtAllChkBx"> <CheckBox Name="cbxAll" Content="All" IsChecked="{Binding Path=DataContext

Why does one of MY WPF DataGrids give the “'EditItem' is not allowed for this view” exception?

自古美人都是妖i 提交于 2020-01-02 10:06:40
问题 I have read all the Q&A I could find here and on the MS forums about this exception, and tried most of the suggestions that I understood, and a few others. It seems that this exception can come up for a wide range of causes. As with others, I have a WPF DataGrid bound to a collection, which throws this exception when one tries to edit one of the cells. They are set to be write-able, the collection is an ObservableCollection, I've implemented get and set handlers which send notification

Datagrid template with rounded corners

纵饮孤独 提交于 2020-01-02 10:02:25
问题 I'm creating DataGrid template with rounded corners, but I faced with this problem: Bottom corners are out of the border bounds. How to solve this? I've read this article: http://diptimayapatra.wordpress.com/2010/06/28/rounded-corner-datagrid-in-wpf/ I need to do the same, but in Template. Here is my DataGrid Template Code: <Style TargetType="{x:Type DataGrid}"> <Setter Property="Background" Value="{StaticResource ControlContentBrush}"/> <Setter Property="RowDetailsVisibilityMode" Value=

Datagrid template with rounded corners

陌路散爱 提交于 2020-01-02 10:00:13
问题 I'm creating DataGrid template with rounded corners, but I faced with this problem: Bottom corners are out of the border bounds. How to solve this? I've read this article: http://diptimayapatra.wordpress.com/2010/06/28/rounded-corner-datagrid-in-wpf/ I need to do the same, but in Template. Here is my DataGrid Template Code: <Style TargetType="{x:Type DataGrid}"> <Setter Property="Background" Value="{StaticResource ControlContentBrush}"/> <Setter Property="RowDetailsVisibilityMode" Value=