简体   繁体   中英

What is the difference between ListView and GridView in WPF?

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?

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM