wpfdatagrid

Improve WPF DataGrid performance

╄→尐↘猪︶ㄣ 提交于 2019-11-27 06:49:30
In my .NET 3.5 WPF Application, I have a WPF DataGrid which will be populated with 500 columns and 50 rows. The performance of App is very very poor in scrolling, or when I do DataGrid.Items.Refresh() or in selecting rows. Actually App will take around 20 sec to Update Layout. Layout_Updated() event will trigger after 20 sec. If I reduce the columns to 50 or less, App will be very responsive. As per my findings performance is directly related to column count. How do I improve the DataGrid performance? Alan There are a few options you can turn on to help you on your DataGrid object

Using WPF DataGridComboBoxColumn with MVVM - Binding to Property in ViewModel

非 Y 不嫁゛ 提交于 2019-11-27 06:43:17
问题 I'm using the excellent MVVM Light Toolkit. My ViewModel exposes: public const string CourtCodesTypeCourtPropertyName = "CourtCodesTypeCourt"; private List<CourtType> _courtCodesTypes = new List<CourtType>(); public List<CourtType> CourtCodesTypeCourt { get { return _courtCodesTypes; } set { if (_courtCodesTypes == value) { return; } var oldValue = _courtCodesTypes; _courtCodesTypes = value; // Update bindings and broadcast change using GalaSoft.MvvmLight.Messenging RaisePropertyChanged

How to use a factory for DataGrid.CanUserAddRows = true

江枫思渺然 提交于 2019-11-27 05:40:47
问题 I would like to use the DataGrid.CanUserAddRows = true feature. Unfortunately, it seems to work only with concrete classes which have a default constructor. My collection of business objects doesn't provide a default constructor. I'm looking for a way to register a factory that knows how to create the objects for the DataGrid. I had a look at the DataGrid and the ListCollectionView but none of them seems to support my scenario. 回答1: The problem: "I'm looking for a way to register a factory

How to loop over the rows of a WPF toolkit Datagrid

限于喜欢 提交于 2019-11-27 05:38:09
I have the next code where I defined a WPF toolkit datagrid control called dgQuery; I filled this one with information of a dataset, then I inserted a new checkbox column in dgQuery to check/uncheck some of the rows, I show part of my C# code: dgQuery.DataContext = dS.Tables[0]; DataGridTemplateColumn cbCol = new DataGridTemplateColumn(); cbCol.Header = "Opc"; FrameworkElementFactory factory = new FrameworkElementFactory(typeof(CheckBox)); Binding bind = new Binding("IsSelected"); bind.Mode = BindingMode.TwoWay; factory.SetValue(CheckBox.IsCheckedProperty, bind); DataTemplate cellTemplate =

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

[亡魂溺海] 提交于 2019-11-27 05:33:01
问题 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

How to bind xml to the WPF DataGrid correctly?

前提是你 提交于 2019-11-27 04:54:18
I have looked for and tried various solutions but so far none of them solve my problem. I am using the built-in DataGrid from WPF in Visual Studio 2010/.NET4 to display data from an XML document stored as an XDocument. My code all runs fine, and I have verified that the XDocument is present and correct. The DataGrid does not display any data, however. The XML looks like this (simplified for clarity): <data> <track> <id>211</id> <name>Track Name</name> <duration>156</duration> <artist_id>13</artist_id> <artist_name>Artist Name</artist_name> <album_id>29</album_id> <album_name>Album Name</album

DataGridTextColumn Visibility Binding

可紊 提交于 2019-11-27 04:32:48
I'm trying to bind column visibility to that of another element like this: <Window x:Class="WpfApplication1.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="MainWindow" Height="350" Width="525"> <Window.Resources> <BooleanToVisibilityConverter x:Key="BooleanToVisibilityConverter" /> </Window.Resources> <StackPanel> <CheckBox x:Name="chkColumnVisible" Content="Show column" /> <DataGrid x:Name="MyDataGrid" AutoGenerateColumns="False"> <DataGrid.Columns> <DataGridTextColumn Header="Column1" Visibility="

'DeferRefresh' is not allowed during an AddNew or EditItem transaction

╄→гoц情女王★ 提交于 2019-11-27 03:14:37
问题 I have a tab control in the GUI and there is WPF 4.0 datagrid in one of the tabs. When I click on a cell in the grid and edit something and then switch tabs, I get a Defer Refresh error: DeferRefresh' is not allowed during an AddNew or EditItem transaction. So I call datagrid.CancelEdit(DataGridEditingUnit.Row) when tab is switched to cancel any pending edit and the Defer refresh issue is gone. But what I really want to do is CommitEdit() so that the user doesn't have to reenter the data

WPF StringFormat on Label Content

痞子三分冷 提交于 2019-11-27 03:11:42
I want to format my string binding as Amount is X where X is a property bound to a label. I've seen many examples but the following doesn't work: <Label Content="{Binding Path=MaxLevelofInvestment, StringFormat='Amount is {0}'}" /> I've also tried these combinations: StringFormat=Amount is {0} StringFormat='Amount is {}{0}' StringFormat='Amount is \{0\}' I even tried changing the binding property's datatype to int , string and double . Nothing seems to work. This is a very common use case but doesn't seem to be supported. Ray Burns The reason this doesn't work is that the Label.Content

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

陌路散爱 提交于 2019-11-27 02:55:06
问题 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 回答1: 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