wpfdatagrid

Dynamically add Columns to DataGrid in wpf

可紊 提交于 2019-12-12 09:44:44
问题 I am currently working on a custom canvas and in that i have to add a table,So i thought dataGrid would be fine. SO i Want to create a " Table" from "Datagrid" by which user can add a table to the canvas at runtime. Till now, I have tried to Populate DataGrid With a list and succeded. How Can I add Columns to a Datagrid at runtime,such that the number of columns and header value Would be taken from the user at runtime using a textbox and based on the value of the textbox the datagrid should

Retain DataGrid IsSelectionActive when a ContextMenu opens in WPF?

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-12 08:36:10
问题 I have a DataGrid which has a style for IsSelectionActive ; however, as soon as the ContextMenu opens, the grid loses IsSelectionActive and it looks like to the user that as if the context menu somehow took the selection and may confuse the user. Is there a way to retain IsSelectionActive when a context menu opens? <ControlTemplate.Triggers> <MultiTrigger> <MultiTrigger.Conditions> <!--<Condition Property="Selector.IsFocused" Value="True" />--> <Condition Property="IsSelected" Value="True" />

WPF datagrid: disable editing in certain rows

核能气质少年 提交于 2019-12-12 08:27:29
问题 I have something like orders table bound to a DataGrid . I want to disable editing on rows, where order date is expired (deadline date > current date): show them greyed and ban entering into edit mode. Here is what I have: <Style TargetType="{x:Type WPFToolkit:DataGridRow}"> <Style.Triggers> <MultiTrigger> <MultiTrigger.Conditions> <!-- ??? order_date > current_date --> <!-- some other condition - already works --> </MultiTrigger.Conditions> <Setter Property="IsEnabled" Value="False"/>

wpf why get “NullReferenceException” when binding SelectedItem [Edit]

不打扰是莪最后的温柔 提交于 2019-12-12 06:18:04
问题 I had a DataGrid, include expander. I want to unselect all rows when expander click, so I call dg.UnSelectAll() or dg.UnSelectAllCells() . But, always get NullReferenceException. I don't know what happening. Edit: My DataGrid Do something, include some style code. Xaml <Style x:Key="GroupHeaderStyle" TargetType="{x:Type GroupItem}"> <Setter Property="Template"> <Setter.Value> <ControlTemplate> <!--<Expander IsExpanded="{Binding Mode=TwoWay, Path=IsSelected, RelativeSource={RelativeSource

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

倖福魔咒の 提交于 2019-12-12 04:44:35
问题 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

Disable DataGridRows depending on a bool flag in WPF

醉酒当歌 提交于 2019-12-12 03:25:34
问题 I would like to gray out and disable specific rows in datagrid. All rows which have the bool flag IsEnabled set to false should be grayed out and disabled for editing. How can I achieve that? Below you can find my Example Code: MainWindow.xaml <Window x:Class="WpfApplicationDisableRows.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:local="clr-namespace:WpfApplicationDisableRows" Title="MainWindow"

WPF Embedded Database Application [closed]

独自空忆成欢 提交于 2019-12-12 02:34:09
问题 Closed . This question needs to be more focused. It is not currently accepting answers. Want to improve this question? Update the question so it focuses on one problem only by editing this post. Closed 4 years ago . I'm new with WPF and I want to make a small application with the embedded (local) database in WPF. I'm using VS08 , --> add new file --> local Database. I can also add a table (test table called Person with Name and Age). And now comes my problem, could anyone tell me how to make

Bind CommandParameter to DataItem for a Button in a DataGrid

不羁的心 提交于 2019-12-12 02:22:02
问题 I have a button in a DataGrid. I need to bind the CommandParameter of this button to the DataItem so that the Predicate of its command will receive information on which piece of data is connected to the button of a given row. I am using MVVM. Thus far, all objects have been bound rather than using explicit naming or event handlers. The button is being used in the data filtering process. The command works because the ICollectionView object in my ViewModel gets the correct CurrentItem when a

Programmatically edit a datagrid cell in wpf

流过昼夜 提交于 2019-12-12 02:16:23
问题 I want to edit the cell not its value but its background color. I know the rowIndex and the columnIndex. But to travese through the grid is a hard part. I just want something like DataGrid.Rows[0][3].BackgroundColor=WhateverIWant Even looping with the help of VisualTreeHelper will work, but kindly guide me through it. Thanks 回答1: Use following method: public static DataGridCell GetDataGridCell(DataGrid grid, int rowIndex, int colIndex) { DataGridCell result = null; DataGridRow row =

WPF add datagrid row from other window

我怕爱的太早我们不能终老 提交于 2019-12-12 01:45:46
问题 I have an add movie window: private void button1_Click(object sender, RoutedEventArgs e) { string name = txtName.Text; string genre = txtGenre.Text; bool dubbed = checkBox1.IsChecked.Value; bool is3d = checkBox2.IsChecked.Value; MessageBox.Show(name + " " + genre); var main = new MainWindow(); main.CallbackAddMovie(name, genre, dubbed, is3d); this.Close(); } And the callback: public class DataItem { public string name { get; set; } public string genre { get; set; } public bool dubbed { get;