Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between ListView and DataGrid in WPF?

I have to retrieve some questions from the database and display them on the user screen dynamically. I also need to add some controls in the columns of grid view, basically a question and input box for an answer.

Please suggest which one should I use? ListView or DataGrid?

like image 313
MangoTable Avatar asked Jan 21 '11 23:01

MangoTable


People also ask

What is the difference between list view and GridView?

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.

What is the difference between grid and DataGrid in WPF?

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.

Which is better ListView or DataGridView?

If you want simple data display then a ListView may be better. If you want data-binding and complex functionality using a DataGridView is better. The Windows Forms ListView control displays a list of items with icons. You can use a list view to create a user interface like the right pane of Windows Explorer.

What is the difference between list view and GridView in C#?

The main difference between a ListView/GridView and a DataGrid is that the latter provides editing and sorting functionality out of the box. So if you don't require to be able to edit and/or sort the data to be displayed in a tabular grid, then choose a ListView with a GridView.


2 Answers

Well, in WPF the difference between ListView and DataGrid is just one. Editing. You need editing use DataGrid, otherwise use ListView. You can edit in ListView also but it is easier and build in DataGrid. Otherwise, whatever can be displayed in DataGrid, can be displayed in ListView.

One thing which DataGrid supports and ListView doesn't (out of the box) is automatic column generation.

You can read this article on CodeProject for a better understanding of DataGrid and also about the major differences between ListView and DataGrid.

like image 81
Yogesh Avatar answered Sep 19 '22 17:09

Yogesh


I'm not a WPF expert, but it terms of just the controls themselves.

When thinking of ListView think Windows Explorer, the pane where you see all you're files, thats a ListView.

When thinking data base its usually (I said usually) a data grid, mouse over the gridview tag and read the description.

Some very obvious reasons why you would want a gridview is its directly editable. You can have your user enter the questions and the answer in there. Note, since ListViewItem is an Content Control you also could customize it easily like this article does.

Also see if this GridView tutorial helps.

You haven't given much of the description of how you need the UI, but you could play around and do anything you like.

You could even make a User Control for a [Question + Input box for Answer]. Then you could use a StackPanel (or even a listview) to list them out.

Hope that helped.

like image 20
gideon Avatar answered Sep 19 '22 17:09

gideon