58

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?

1

2 Answers 2

98

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.

Sign up to request clarification or add additional context in comments.

5 Comments

There are definitelly more differences. One of them is column sizing. In datagrid you can stretch column to fill grid size, in listview you can't. As far as I know, ListView was introduced in WPF 3.5 but was later replaced by DataGrid, but its still present for compatibility reasons
And column sorting.
Worth noting that editing in DataGrid can be turned off using IsReadOnly="True"
Anyone know which is faster when using virtual mode for a large amount of rows?
ListView not supports percent column width.
8

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.