wpfdatagrid

Getting WPF Data Grid Context Menu Click Row

流过昼夜 提交于 2019-11-29 23:09:30
I have a WPF DataGrid <DataGrid AutoGenerateColumns="False" Name="dataGrid1" IsReadOnly="True" > <DataGrid.Columns> <DataGridTextColumn Header="Site" Binding="{Binding Site}" Width="150" /> <DataGridTextColumn Header="Subject" Binding="{Binding Subject}" Width="310" /> </DataGrid.Columns> <DataGrid.ContextMenu> <ContextMenu> <MenuItem Header="Delete" Click="Context_Delete"> <MenuItem.Icon> <Image Width="12" Height="12" Source="Images/Delete.png" /> </MenuItem.Icon> </MenuItem> </ContextMenu> </DataGrid.ContextMenu> </DataGrid> I have the click event handler as: private void Context_Delete

wpf 4.0 datagrid template column two-way binding problem

心已入冬 提交于 2019-11-29 17:00:46
问题 I'm using the datagrid from wpf 4.0. This has a TemplateColumn containing a checkbox. The IsChecked property of the checkbox is set via binding. The problem is that even if I specify the binding mode explicitly to be TwoWay, it works only in one direction. I have to mention that the same code works perfectly in .net 3.5 with the datagrid from the wpf toolkit. Please take a look at the .xaml and .cs contents. Thanks in advance, Roland <Window.Resources> <DataTemplate x:Key=

Hide Datagrid Column based on its Property name

99封情书 提交于 2019-11-29 16:22:04
I have a DataGrid defined as follows : <DataGrid Name="dtMydatagrid" Margin="10,10,10,10" RowHeight="20" AutoGenerateColumns="True" ItemsSource="{Binding}" Height="auto" Width="auto"> <DataGrid.Columns> <DataGridTemplateColumn Header=""> <DataGridTemplateColumn.CellTemplate> <DataTemplate> <TextBox x:Name="TXT" Background="Transparent" Width="15" IsReadOnly="True" Visibility="Hidden" Margin="0,0,0,0"/> <DataTemplate.Triggers> <DataTrigger Binding="{Binding Path=IsBKM}" Value="true"> <Setter Property="Background" Value="AQUA" TargetName="TXT"/> <Setter Property="Visibility" Value="Visible"

unselect row in wpf datagrid

被刻印的时光 ゝ 提交于 2019-11-29 15:48:06
I have <DataGrid Name="grid" MouseDoubleClick="Attributes_MouseDoubleClick" > I need to unselect a row whenever a click event occurs anywhere else other than the Datagrid row. i.e. grid.CurrentItem should be null I need to fire a double-click event only on a row. But, the problem is, once I select a row and double-click elsewhere on the grid(header, empty scrollviewer area, etc) the double-click event fires as expected but the CurrentItem is sometimes the selected row and sometimes null. To prevent this behaviour.. I need to unselect the selected row. Any ideas as to how I should approach this

TwoWay binding on a DataGrid in WPF

吃可爱长大的小学妹 提交于 2019-11-29 15:36:47
I have a WPF DataGrid that I am filling using var allLines = from Lines in ctx.InvoiceLines join PerPs in ctx.ProductsViews on Lines.ProductCode equals PerPs.ProductCode where (Lines.BranchNo == BrNo) && (Lines.Docket == Docket) select new { Lines.ProductCode, Lines.Description, Lines.Inv_Quantity, Lines.Grn_Quantity, Lines.Inv_Price,Lines.Grn_Price,Lines.Inv_Total, Lines.Grn_Total, Lines.AnalCode, Lines.Vat_Rate, Lines.GrnNo,Lines.Comment , PerPs.OuterUnits}; dgGrid.ItemsSource = allLines; I want to use two way binding to update the database when any of the values are changed or when a new

WPF DataGrid default sort not working

不羁岁月 提交于 2019-11-29 14:21:51
I have a DataGrid, with columns XAML as such: <DataGridTextColumn Header="Time" Binding="{Binding Date, StringFormat='yyyy-MM-dd HH:mm:ss'}" SortMemberPath="Date" SortDirection="Descending" Width="130" CanUserResize="True" /> <DataGridTextColumn Header="Level" Binding="{Binding Level}" Width="60" CanUserResize="True" /> <DataGridTextColumn Header="Source" Binding="{Binding Logger}" Width="150" CanUserResize="True" /> <DataGridTextColumn Header="Message" Binding="{Binding Message}" Width="*" CanUserResize="True" /> I bind this to an ObservableCollection<EalsLogEvent> , where EalsLogEvent.Date

How to speed up rendering of vertical scrollbar markers

故事扮演 提交于 2019-11-29 12:52:03
I have a customized vertical scrollbar which displays markers for selected items in a DataGrid. The problem I'm facing is, when there are a great number of items (e.g. could be 5000 to 50000) there is a lag while it is rendering the markers. With the following code it basically renders as per the selected items index, number of items and height of the track. Obviously this is inefficient and am looking for other solutions. This is my customized vertical scrollbar <helpers:MarkerPositionConverter x:Key="MarkerPositionConverter"/> <ControlTemplate x:Key="VerticalScrollBar" TargetType="{x:Type

Can static data for Datagrid rows be defined purely in XAML i.e. no code behind?

痴心易碎 提交于 2019-11-29 11:49:56
问题 I have static data that I want to display in Datagrid format. The values are for display purposes only and will not change. Can it be added as some kind of subtag of the Datagrid control so I can avoid anything in the codebehind? It has to be Datagrid control only as the purpose is to experiment with and demo certain Datagrid UI features with dummy blah blah content. If pure XAML content is not possible then what is the best (quick & dirty) method to set up dummy content for a datagrid? Can

Select DataGridCell from DataGrid

喜夏-厌秋 提交于 2019-11-29 09:45:08
I have a DataGrid WPF control and I want to get a specific DataGridCell . I know the row and column indices. How can I do this? I need the DataGridCell because I have to have access to its Content. So if I have (for example) a column of DataGridTextColum , my Content will be a TextBlock object. You can use code similar to this to select a cell: var dataGridCellInfo = new DataGridCellInfo( dataGrid.Items[rowNo], dataGrid.Columns[colNo]); dataGrid.SelectedCells.Clear(); dataGrid.SelectedCells.Add(dataGridCellInfo); dataGrid.CurrentCell = dataGridCellInfo; I can't see a way to update the contents

Focus on DataGridCell for SelectedItem when DataGrid Receives Keyboard Focus

拥有回忆 提交于 2019-11-29 09:37:02
问题 I have a DataGrid where the SelectedItem is bound to a VM Selected property. I have a search control that will do a find and the SelectedItem of the DataGrid changes (and scrolls into view). WPF 4.0 and DataGrid SelectionUnit="FullRow" . My problem is with the focus. The DataGrid receives focus (via attached property / binding) but you can't use the Up , Down , Page Up , Page Down keys to change rows ( SelectedItem ). If I tab again, the first cell of the first row displayed is selected which