|
-
May 15th, 2010, 10:52 AM
#1
Thread Starter
Fanatic Member
[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
Last edited by HowTo; May 15th, 2010 at 11:19 AM.
-
May 15th, 2010, 11:05 AM
#2
Thread Starter
Fanatic Member
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
Last edited by HowTo; May 15th, 2010 at 11:21 AM.
-
May 15th, 2010, 12:00 PM
#3
Thread Starter
Fanatic Member
Last edited by HowTo; May 15th, 2010 at 01:21 PM.
-
May 15th, 2010, 02:34 PM
#4
New Member
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.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|