I am trying to create a WPF database application. There seems to be a few good components that I can use for showing the data in the database tables. ListView
and GridView
seems to be popular for this usage. But for a novice, it's hard to see the difference between them.
What is the difference between ListView
and GridView
? What are the pros and cons?
The main difference between ListView and GridView is how it lays out its child. With ListView you are laying your children one by one either vertically or horizontally only. With GridView, its a combination of both. It lays its children horizontally first.
A Grid is a control for laying out other controls on the form (or page). A DataGrid is a control for displaying tabular data as read from a database for example.
The GridView view mode displays a list of data items by binding data fields to columns and by displaying a column header to identify the field. The default GridView style implements buttons as column headers.
The main difference between a ListView/GridView and a DataGrid is that the latter provides editing and sorting functionality out of the box.
A ListView is a WPF control, deriving from ListBox, that (in theory) can render the items using one of several view modes which are derived from ViewBase. GridView is the only one implemented. So in other words, it's not a choice of ListView or GridView. If you want to display tabular data in a ListView, you would create a ListView and set its View to a GridView (which defines the column layout.)
The reality, however, is that as far as I know, no other views were implemented. And because ListView is not a very feature-rich control, it's largely obsolete at this point. In fact, Silverlight does not even provide ListView.
There is a DataGrid control that is very close in functionality and API to the Silverlight DataGrid control and you should probably use this instead of a ListView.
A ListView
is the object that holds the data:
ListView is an ItemsControl, which means it can contain a collection of objects of any type (such as string, image, or panel). For more information, see the ItemsControl class.
The presentation of the data items in a ListView is defined by its view mode, which is specified by the View property. Windows Presentation Foundation (WPF) provides a GridView view mode that partitions the ListView data item content into columns. The properties and methods on GridView and its related classes style and specify the content of the columns.
whereas a GridView
controls how that data is represented:
Represents a view mode that displays data items in columns for a ListView control.
The GridView class and its supporting classes provide the infrastructure to display data items that are specified for a ListView control in a series of columns.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With