-
[RESOLVED] DataGrid
when i used to program in windows application using the datagridview then i used to bind the datatable with the datasource propertyof the datagridview. now in wpf,i just added a datagrid and tried to do thesame way but in vain........... Please help thank you
-
Re: DataGrid
Code:
Imports System.Data
Imports System.Data.OleDb
Class MainWindow
Dim con As OleDbConnection
Dim cmd As OleDbCommand
Private Sub MainWindow_Loaded(ByVal sender As Object, ByVal e As System.Windows.RoutedEventArgs) Handles Me.Loaded
con = New OleDbConnection("Provider=Microsoft.Jet.Oledb.4.0;Data Source=db1.mdb")
con.Open()
cmd = New OleDbCommand("Select * from Table1", con)
Dim da As New OleDbDataAdapter(cmd)
Dim dt As New System.Data.DataTable
da.Fill(dt)
DataGrid1.DataContext = dt.DefaultView
Code:
<Window x:Class="MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525">
<Grid>
<DataGrid ItemsSource="{Binding}" AutoGenerateColumns="False" Height="200" HorizontalAlignment="Left" Margin="128,49,0,0" Name="DataGrid1" VerticalAlignment="Top" Width="200" DataContext="{Binding}" />
</Grid>
</Window>
I did this but in vain........no data is displayed in the datagrid..........please help
-
Re: DataGrid
-
Re: [RESOLVED] DataGrid
To show data in WPF grid, you bind itemsSource=tableOjbect.Defaultview.
Although as I've stated on the thread above, have you try to change your sqlSelectCommand to a different select statement and try to "refresh" the binding to the grid? I'm having problem with that. My grid will not show the new set of data. It will simply show the old data's columns heading and ZERO rows of data.