ListBox vs. ListView - how to choose for data binding
Asked Answered
V

1

329

I'm considering either a ListBox or a ListView for a WPF application. It seems either supports data binding and item templates. My application has a simple list of items that I intend to be able to search/sort/filter based on user input. The data binding demo (http://msdn.microsoft.com/en-us/library/ms771319.aspx) uses a ListBox with a CollectionViewSource.

Does anyone have pros/cons for which control to use and when?

Vesting answered 22/10, 2008 at 19:35 Comment(0)
A
376

A ListView is a specialized ListBox (that is, it inherits from ListBox). It allows you to specify different views rather than a straight list. You can either roll your own view, or use GridView (think Explorer-like "details view"). It's basically the multi-column ListBox, the cousin of Windows Forms' ListView.

If you don't need the additional capabilities of ListView, you can certainly use ListBox if you're simply showing a list of items (Even if the template is complex).

Asparagus answered 22/10, 2008 at 20:10 Comment(1)
What's the difference between that and DataGrid? Unless ListView enables you to change the view dynamically (like win-explorer - list, details, large icons), I don't see why using it...Do

© 2022 - 2024 — McMap. All rights reserved.