-
DataGridView in WPF
Hi All.
I found interesting code to use DataGridView in WPF.
XAML
Code:
<Window x:Class="Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:WinForms="clr-namespace:System.Windows.Forms;assembly=System.Windows.Forms"
Title="Window2" Height="300" Width="300">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="*"></RowDefinition>
</Grid.RowDefinitions>
<WindowsFormsHost Grid.Row="0">
<WinForms:DataGridView x:Name="myDG">
</WinForms:DataGridView>
</WindowsFormsHost>
</Grid>
</Window>
VB code
Code:
Imports System.Windows.Data
Imports System.Windows.Forms.Integration
Imports System.Data
Partial Public Class Window1
Public Sub New()
InitializeComponent()
Dim dt As New DataTable()
dt.Columns.Add("Col1", GetType(String))
dt.Columns.Add("Col2", GetType(String))
dt.Rows.Add("Hello", "World")
dt.Rows.Add("Green", "Apple")
dt.Rows.Add("Big", "Orange")
dt.Rows.Add("Fresh", "Water")
myDG.DataSource = dt
End Sub
End Class
How to modify this code using DataSet and TableAdapter?
Thanks.
-
Re: DataGridView in WPF
I would assume just set the datasource of the grid to the dataset that is bound to the tableadapter. Just like WinForms.
-
Re: DataGridView in WPF
So many people don't seem to realise what a DataSet is. It's just a container for Datatables really. The code you have already assigns a DataTable to the grid's DataSource. You will be calling Fill on your TableAdapter to populate a DataTable that is contained within the DataSet. You simply assign that DataTable to the grid's DataSource.
-
Re: DataGridView in WPF