wpfdatagrid

how to handle group subtotal and e.g. target rows in WPF DataGrid?

廉价感情. 提交于 2019-11-29 09:26:55
I'm implementing a WPF DataGrid that contains projects with many key figures. Projects are grouped by project categories. For each category there should be: a row that shows in each key figure column sum of all rows for the column. a target row that is not part of the datasource grid in binded to. target row tells for every column what is target for the year (e.g. how much money there's to spend). These rows should be always on top in each group (sorting filtering). My 1st solution was to have this data in group header. This is not a good solution because group header does not support columns.

Show “No record found” message on a WPF DataGrid when it's empty

浪子不回头ぞ 提交于 2019-11-29 09:24:45
If there is no record available, I want to add a TextBlock on data grid, below the header, showing the message "No Record Found." Consider the attached image for reference. Its been a long time since the question has been posted. But I thought this might be useful to someone else. <Window.Resources> <BooleanToVisibilityConverter x:Key="BooleanToVisibilityConverter" /> </Window.Resources> <DataGrid Name="dgProjects" ItemsSource="{Binding Projects}" AutoGenerateColumns="True" /> <TextBlock Text="Employee has no projects" Visibility="{Binding Items.IsEmpty, Converter={StaticResource

How do I bind the background of a data grid row to specific color?

微笑、不失礼 提交于 2019-11-29 09:11:06
I have a observable collection that binds to a data grid. I also have in the view model a color property and I want to bind the background of each row in the data grid to the color property on the vm. You can bind the Background in the RowStyle for DataGrid <DataGrid ...> <DataGrid.RowStyle> <Style TargetType="DataGridRow"> <Setter Property="Background" Value="{Binding MyBackground}"/> </Style> </DataGrid.RowStyle> <!-- ... --> </DataGrid> This will work if MyBackground is a Brush . You mention in your question that you have a Color , if this is the case you can use this instead <Setter

How to bind collection to WPF:DataGridComboBoxColumn

一笑奈何 提交于 2019-11-29 09:09:19
Admittedly I am new to WPF but I have looked and looked and can't find a solution to this problem. I have a simple object like: class Item { .... public String Measure { get; set; } public String[] Measures {get; } } Which I am trying to bind to a DataGrid with two text columns and a combo box column. For the combo box column, property Measure is the current selection and Measures the possible values. My XAML is: <DataGrid Name="recipeGrid" AutoGenerateColumns="False" CellEditEnding="recipeGrid_CellEditEnding" CanUserAddRows="False" CanUserDeleteRows="False"> <DataGrid.Columns>

Date Converter using WPF

人盡茶涼 提交于 2019-11-29 07:57:48
public class DateTimeConverter : IValueConverter { #region IValueConverter Members public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) { if (values != null) { DateTime test = (DateTime) value ; string date = test.ToString("d/M/yyyy"); return (date); } return string.Empty; } public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) { throw new NotImplementedException(); } #endregion } I made this converter to get the current time once the date is selected from the DatePicker.

DataGrid RowDetails Width problem

给你一囗甜甜゛ 提交于 2019-11-29 07:07:35
问题 Suppose I have a DataGrid that is defined like this <DataGrid AreRowDetailsFrozen="True" ItemsSource="{Binding MyCollection}" AutoGenerateColumns="False"> <DataGrid.RowDetailsTemplate> <DataTemplate> <Border CornerRadius="5" BorderBrush="Red" BorderThickness="2" Background="Black"> <TextBlock Foreground="White" Text="{Binding RowDetails}" TextWrapping="Wrap"/> </Border> </DataTemplate> </DataGrid.RowDetailsTemplate> <DataGrid.Columns> <DataGridTextColumn Header="0" Binding="{Binding Value1}"/

How to set the DataSource of a DataGrid in WPF?

杀马特。学长 韩版系。学妹 提交于 2019-11-29 06:45:36
I need to set a table from a database to be the DataSource of a GridGrid in WPF. In Windows Forms the property is called DataSource but in WPF no such property exists, so how can i do it? You can use the ItemsSource property : <ListView ItemsSource="{Binding YourData}"> <ListView.View> <GridView> <!-- The columns here --> </GridView> </ListView.View> </ListView> If you prefer to use code-behind rather than a binding, just give a name to the ListView and set the ItemsSource property in code: listView1.ItemsSource = YourData; You can also use the ItemsSource property with other list controls (

Event for Select All: WPF Datagrid

廉价感情. 提交于 2019-11-29 04:14:42
I am using WPF data-grid. In data-grid user have column-headers and row-headers. When column-headers and row-headers both of them are visible, in the top left corner we have one small square section available. (cross section in the top left corner where the column and row headers meet.) when we click on that it selects all the cells within data-grid. Is there any event for that? If not how can trap that event. Please guide me. Do let me know if you need any other information regarding this problem. Regards, Priyank The datagrid handles the routed command ApplicationCommand.SelectAll, so if the

Code to check if a cell of a DataGrid is currently edited

一曲冷凌霜 提交于 2019-11-29 02:00:50
Is there a simple possibility to check if the DataGrid is currently in EditMode (Without to subscribe to BeginningEdit and CellEditEnding) It seems you can also get this information from the items view, namely this works: IEditableCollectionView itemsView = stateGrid.Items; if (itemsView.IsAddingNew || itemsView.IsEditingItem) { stateGrid.CommitEdit(DataGridEditingUnit.Row, true); } I have not confirmed this but most likely you could get these flags in a viewmodel if your bound collection provides an IEditableCollectionView. Ok, I havent found a simple solution and no one pointed me to one.

WPF Datagrid Row Editing “ENDED” event

喜欢而已 提交于 2019-11-29 01:43:27
问题 I know that WPF datagrid has "RowEditEnding" event , but I need to fire the event on after the Row has comitted to check if the newly added row is duplicated and merge the duplicated row. My datagrid has "CanUserAddRow" property set to True. I am using EntityObservableCollection that extends ObservableCollection to synchronize my entity with the collection. So, i considered OnCollectionChanged event, but the "InsertItem" event is raise once user click on the new item place holder row, which