Results 1 to 4 of 4

Thread: DataGridView in WPF

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Nov 2006
    Posts
    176

    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.

  2. #2
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373

    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.

  3. #3
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    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.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  4. #4
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: DataGridView in WPF

    Thread closed, continued here - http://www.vbforums.com/showthread.php?t=563220

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width