WPF DataGrid 与 Windows 窗体 DataGridView

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4613394/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-08 22:28:31  来源:igfitidea点击:

WPF DataGrid Vs Windows Forms DataGridView

wpfwinformsdatagriddatagridviewwpfdatagrid

提问by markmnl

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?

我有 WPF 和 Windows 窗体的经验,但是只使用了 Windows 窗体 DataGridView 而不是 WPF DataGrid(它只包含在 .Net 4 中,或者可以从 Codeplex 添加到 .Net 3.5,我理解)。我将要开发一个应用程序,大量使用这些控件之一来处理大量数据,并且读取性能是 WPF DataGrid 的一个问题,所以我可能会坚持使用 Windows Forms DataGridView .. 是这种情况吗?

I do not want to use a 3rd party control.

我不想使用第 3 方控件。

Does the Windows Forms DataGridView offer significant performance over the WPF DataGrid for large amounts of data?

对于大量数据,Windows 窗体 DataGridView 是否比 WPF DataGrid 提供显着的性能?

If I were to use WPF I would prefer to use .Net 3.5S SP1, unless the DataGrid in the .Net 4 is significantly better?

如果我要使用 WPF,我宁愿使用 .Net 3.5S SP1,除非 .Net 4 中的 DataGrid 明显更好?

Also I want to use ADO with DataTable's which I feel is better suited to Windows Forms..

此外,我想将 ADO 与 DataTable 一起使用,我觉得它更适合 Windows 窗体。

回答by ColinE

For your needs, unless you have other requirements that steer you towards WPF, I would recommend the WinForms DataGridView.

根据您的需要,除非您有其他要求引导您使用 WPF,否则我会推荐 WinForms DataGridView。

The WPF DataGrid was made available via Codeplex, as an 'out of band' release, i.e. these are control that will eventually make their way into the WPF APIs, but are released on codeplex early so that we can benefit from them before the next major .NET release. You can use either the .NET 4.0 or codeplex DataGrid. As far as I know they are one and the same. The WPF DataGrid plays quite nicely with DataTables. See the examples in my following article:

WPF DataGrid 是通过 Codeplex 提供的,作为“带外”版本,即这些是最终将进入 WPF API 的控件,但在 Codeplex 上提前发布,以便我们可以在下一个主要版本之前从它们中受益.NET 版本。您可以使用 .NET 4.0 或 codeplex DataGrid。据我所知,它们是一回事。WPF DataGrid 与 DataTables 配合得很好。请参阅我以下文章中的示例:

http://www.codeproject.com/KB/WPF/WPFDataGridExamples.aspx

http://www.codeproject.com/KB/WPF/WPFDataGridExamples.aspx

However, the WPF framework and visuals are slightly more heavyweight than WinForms. Also, the WinForms DataGridView is very mature.

但是,WPF 框架和视觉效果比 WinForms 稍微重量级一些。此外,WinForms DataGridView 非常成熟。

For very large datasets, the WinForms DataGridView has one feature that is not present in the WPF DataGrid, which is vital for very large grids (millions of rows), this is a virtual mode:

对于非常大的数据集,WinForms DataGridView 具有 WPF DataGrid 中不存在的一项功能,这对于非常大的网格(数百万行)至关重要,这是一种虚拟模式:

http://msdn.microsoft.com/en-us/library/ms171622.aspx

http://msdn.microsoft.com/en-us/library/ms171622.aspx

Known also as Data-Virtualization. In this mode, you tell the grid how many rows there are in your data, then handle events to populate the cells. This scales very well. I have used this for massive and complex grids.

也称为数据虚拟化。在这种模式下,您告诉网格数据中有多少行,然后处理事件以填充单元格。这很好地扩展。我已经将它用于大规模和复杂的网格。

WPF has UI virtualization which is a form of UI control recycling, but not data virtualization.

WPF 具有 UI 虚拟化,这是一种 UI 控件回收的形式,但不是数据虚拟化。

Hope that helps.

希望有帮助。

回答by David

For any beginners (like me) making this decision, WindowsForms is tremendously easier to use. Of course, there are a lot of other reasons to use WPF that might influence your decision, but if your project is primarily a DataGrid, then WinForms is the way to go.

对于做出此决定的任何初学者(如我)来说,WindowsForms 非常易于使用。当然,使用 WPF 的其他原因可能会影响您的决定,但如果您的项目主要是 DataGrid,那么 WinForms 是您的最佳选择。

回答by Alex Fatkin

You can use a DataGrid WPF as a DataGridView if you at first fill ItemsSource of the DataGrid .

如果您首先填充 DataGrid 的 ItemsSource ,则可以将 DataGrid WPF 用作 DataGridView 。

MyDataGrid.ItemsSource = MySource;
MyDataGrid.Columns[0].Width = 300;
MyDataGrid.Columns[0].Header = "MyName";

回答by abmv

Check Xceed datagrid for WPF which is way better than WPF DataGrid but that is 3rdparty but worth it.

检查 Xceed datagrid for WPF 这比 WPF DataGrid 好得多,但这是 3rdparty 但值得。

回答by Dmitriy

WPF DataGrid much more faster, I think. But when I try to use WPF DataGrid for big amount of data (a lot of columns (about 40-50) and rows) with styles it working slow (horizontal scrolling). DataGrid from 3rd party controls working much better (I use Infragistics XamDataGrid).

我认为 WPF DataGrid 快得多。但是当我尝试使用 WPF DataGrid 处理大量数据(很多列(大约 40-50)和行)时,它的样式工作缓慢(水平滚动)。来自 3rd 方控件的 DataGrid 工作得更好(我使用 Infragistics XamDataGrid)。