You can use the ItemsSource property:
<ListView ItemsSource="{Binding YourData}"> <ListView.View> <GridView> </GridView> </ListView.View> </ListView>
If you prefer to use code binding instead of binding, just provide the ListView name and set the ItemsSource property in the code:
listView1.ItemsSource = YourData;
You can also use the ItemsSource property with other list controls ( DataGrid , ListBox , ComboBox , etc.), as it is defined in the base class ItemsControl .
EDIT: if the data source is a DataTable , you cannot assign it directly to the ItemsSource , because it does not implement IEnumerable , but you can do it through a binding:
listView1.SetBinding(ItemsControl.ItemsSourceProperty, new Binding { Source = YourData });
Thomas levesque
source share