Categories
data-binding listbox listview wpf

ListBox vs. ListView – how to choose for data binding

328

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?

0

    375

    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 form’s 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).

    1

    • 4

      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…

      – JobaDiniz

      May 27, 2017 at 12:53