I need to set a table from a database to be the DataSource of a GridGrid in WPF. In Windows Forms the property is called DataSource
but in WPF no such property exists, so how can i do it?
相关问题
- VNC control for WPF application
- WPF Binding from System.Windows.SystemParameters.P
- XAML: Applying styles to nested controls
- How can I add a horizontal line (“goal line”) for
- How to properly change a resource dictionary
The
GridView
is a view and not a standalone control as far as i know, you would normally use it as the view of aListView
. In WPF the property for data population is calledItemsSource
, you probably want to either use aListView
orDataGrid
to display your data that way.You can use below both ways to bind the datatable to datagrid in WPF.
You can use the
ItemsSource
property :If you prefer to use code-behind rather than a binding, just give a name to the
ListView
and set theItemsSource
property in code:You can also use the
ItemsSource
property with other list controls (DataGrid
,ListBox
,ComboBox
, etc), since it is defined in theItemsControl
base class.EDIT: if the data source is a
DataTable
, you can't assign it directly toItemsSource
because it doesn't implementIEnumerable
, but you can do it through a binding:This is simple an example:
XAML part :
C# part :
... [code to read and fill your table ] ...
And now your DataGrid will be filled with your DataTable