How do I enable DataGridView?
Currently it is greyed out in the toolbox, see this screenshot.
DataGridView is a Windows Forms control, as your screenshot shows. Putting WinForms in WPF is usually avoided where possible as they are different technologies - you should aim to use a WPF equivalent.
If you really want to use it, you can use a WindowsFormsHost - there are lots of guides out there to explain how.
In fact, DataGrid is the WPF equivalent of DataGridView, e.g. WPF DataGrid Vs Windows Forms DataGridView. I'd use DataGrid if I were using WPF.
Related
I am trying to add a DataGrid to my Windows Forms application and it seems that it is missing from the toolbox. Only DataGridView is available.
PS: I was able to manually add it to designer code. But nevertheless I am curious as to why it's not included in the toolbox.
I suspect the DataGrid was never in the Toolbox to begin with. According to MSDN, the DataGrid
Displays ADO.NET data in a scrollable grid. The DataGridView control
replaces and adds functionality to the DataGrid control; however, the
DataGrid control is retained for both backward compatibility and
future use, if you choose.
Also, you should note that Visual Studio allows you to customize the items in the Toolbox. You can right click in the Toolbox, select "Choose Items" and then select DataGrid so that it will then appear in your toolbox.
I'm new to WPF and I'm wondering is there anyway to have elements from Winforms toolbox in WPF. I mean the Winforms toolbox has a lot of elements and they're not present in WPF toolbox. for example something like PerformanceCounter in Winforms toolbox is not found in WPF toolbox.
thanks in advance
There are some controls that didn't get represented in WPF, but you can use WindowsFormsHost. As the name indicates, it's purpose is to host the Windows Forms elements.
Walkthrough: Hosting a Windows Forms Control in WPF
I would add that things like PerformanceCounter you can use in code, rather than placing it on a form. Other elements which do have a UI purpose can be placed inside a WindowsFormsHost control. I do this with ReportViewer -- it's a Windows Forms control that has no WPF equivalent.
Is there any site available where I can find free WPF controls like Griview ? I am currently working on a complex project where I need a customizable WPF Gridview like telerik
You can use controls from the WPF Toolkit as well as Extended WPF Toolkit.
Have a look at the controls in AvalonControlsLibrary on code plex, it is having a DataGridView control apart from other controls. -
http://avaloncontrolslib.codeplex.com/wikipage?title=Home&ProjectName=avaloncontrolslib
DataGridView
DataGridView is a maybe a misleading name for this control. This control is far from being the same as the WinForms DataGridView (maybe someday it will J). Basically this control is a WPF ListView control but it is capable of auto generate the GridViewColumns for you. It generates the columns by looking at the objects’ properties. You can also specify how you generate the columns by decorating your properties with a custom attribute. For more information have a look at this post. http://marlongrech.wordpress.com/2007/09/01/listview-with-auto-generation-of-column-enable-disable-columns/
Similar SF question - Where can I find free WPF controls and control templates?
On codeplex.com and codeproject.com. However the best always cost money.
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 were to use WPF I would prefer to use .Net 3.5S SP1, unless the DataGrid in the .Net 4 is significantly better?
Also I want to use ADO with DataTable's which I feel is better suited to Windows Forms..
For your needs, unless you have other requirements that steer you towards WPF, I would recommend the 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:
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.
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:
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.
Hope that helps.
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.
You can use a DataGrid WPF as a DataGridView if you at first fill ItemsSource of the DataGrid .
MyDataGrid.ItemsSource = MySource;
MyDataGrid.Columns[0].Width = 300;
MyDataGrid.Columns[0].Header = "MyName";
Check Xceed datagrid for WPF which is way better than WPF DataGrid but that is 3rdparty but worth it.
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).
Is there a DataGrid component that behaves the same in WPF and Silverlight? There are some small differences in DataGrids from MS (WPF and Silverlight Toolkits). For example, while WPF version has CanUserAddRows property, Silverlight version does not.
I gave up - there nothing like that so I have to care about differences in the code by myself.
Edit: Most of the differences can be handled by styles - simply create one DataGrid style for WPF and one for Silverlight.