wpfdatagrid

How to show row-number in first column of WPF Datagrid

送分小仙女□ 提交于 2019-11-28 09:29:30
While searching I found that, row number can be set to RowHeader easily: void datagrid_LoadingRow(object sender, DataGridRowEventArgs e) { e.Row.Header = e.Row.GetIndex(); } It sets row number in RowHeader. But I want to show Row number to first column Can any one help me how can I achieve this? Thanks There might be an easier way to do this but I got it to work by using the GetIndex() method on the DataGridRow class. This returns the index in to the data source so might not be exactly what you're after. the xaml <Window x:Class="WpfApplication1.MainWindow" xmlns="http://schemas.microsoft.com

WPF DataGrid Vs Windows Forms DataGridView

流过昼夜 提交于 2019-11-28 09:08:51
I have experience in WPF and Windows Forms, however have only used the Windows Forms DataGridView and not the WPF DataGrid (which was only included in .Net 4 or could be added to .Net 3.5 from Codeplex, I understand). I am about to devlop an app using one of these controls heavily for large amounts of data and have read performance is an issue with the WPF DataGrid so I may stick to the Windows Forms DataGridView.. Is this the case? I do not want to use a 3rd party control. Does the Windows Forms DataGridView offer significant performance over the WPF DataGrid for large amounts of data? If I

unselect row in wpf datagrid

我是研究僧i 提交于 2019-11-28 09:07:41
问题 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

TwoWay binding on a DataGrid in WPF

夙愿已清 提交于 2019-11-28 08:46:01
问题 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

Purpose of using FrameworkElementFactory

荒凉一梦 提交于 2019-11-28 08:28:51
问题 In one of the application I am working I have found this code - public class MatrixCellTemplate : ColumnDataTemplate<MatrixCellContainer> { } public class ColumnDataTemplate<T> : DataTemplate where T : FrameworkElement { public ColumnDataTemplate() { FrameworkElementFactory factory = new FrameworkElementFactory(typeof(T)); VisualTree = factory; } } This MatrixCellTemplate is used to set the CellTemplate of a custom DataGridTemplateColumn (later added to DataGrid.Columns collection) like this

WPF DataGrid default sort not working

家住魔仙堡 提交于 2019-11-28 08:02:41
问题 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="*"

WPF datagrid pasting

跟風遠走 提交于 2019-11-28 07:39:40
I'm having trouble pasting from a csv into the wpf datagrid - I have followed the suggestions here http://blogs.msdn.com/b/vinsibal/archive/2008/09/25/pasting-content-to-new-rows-on-the-wpf-datagrid.aspx and the code exectues with no problem - however, it seems that all the new rows are created but only the first row gets populated with data. The data seems to be constantly overwritten so that the last item that is in the clipboard data is populated in the first row and all other rows are blank. I know this must be an index issue or something but I cannot track it down. Also when I have a look

WPF Toolkit DataGrid SelectionChanged Getting Cell Value

无人久伴 提交于 2019-11-28 07:06:23
Please help me, Im trying to get the value of Cell[0] from the selected row in a SelectionChangedEvent. I am only managing to get lots of different Microsoft.Windows.Controls and am hoping im missing something daft. Hoping I can get some help from here... private void datagrid_SelectionChanged(object sender, SelectionChangedEventArgs e) { Microsoft.Windows.Controls.DataGrid _DataGrid = sender as Microsoft.Windows.Controls.DataGrid; } I was hoping it would be something like... _DataGrid.SelectedCells[0].Value; However .Value isn't an option.... Many many thanks this has been driving me mad! Dan

Upgrading to .NET 4.5: An ItemsControl is inconsistent with its items source

允我心安 提交于 2019-11-28 05:21:40
I'm building an application, which uses many ItemControls(datagrids and listviews). In order to easily update these lists from background threads I used this extension to ObservableCollections, which has worked fine: http://geekswithblogs.net/NewThingsILearned/archive/2008/01/16/have-worker-thread-update-observablecollection-that-is-bound-to-a.aspx Today I installed VS12(which in turn installed .NET 4.5), as I want to use a component which is written for .NET 4.5. Before even upgrading my project to .NET 4.5 (from 4.0), my datagrid started throwing InvalidOperationException when updated from a

DataGrid's selected row color when inactive

做~自己de王妃 提交于 2019-11-28 05:11:01
How can I style WPF DataGrid to change the color of selected row when DataGrid lost its focus? After ages of searching, I found a surprisingly simple way to do this that's cleaner than the Got/LostFocus approach posted earlier: <DataGrid.Resources> <SolidColorBrush x:Key="{x:Static SystemColors.InactiveSelectionHighlightBrushKey}" Color="DarkGray"/> </DataGrid.Resources> This just sets the inactive background colour to DarkGray, leaving the active background colour to the default, but you can change that too using the SystemColors.HighlightBrushKey too of course. The foreground resource key