Donate

Simple WPF Datagrid Demo Or Tutorial

I have developed a project on WPF before. WPF has been utilized in Vista OS and other software. But this cannot replace the stability of Windows Forms.
Still, I don't have ample time to dive deeply in WPF, hopefully soon! LOL.. :D
So, to begin with:
1. Download and install WPF Toolkit (Visual Studio 2008)
2. Open Visual Studio 2008
3. Add a WPF Project (Just call it GridDemo)
4. Add a DataGrid in your Window.xaml
5. Make sure to have referenced wpf toolkit: http://schemas.microsoft.com/wpf/2008/toolkit/
6. Customize Your Grid
<grid:DataGrid AutoGenerateColumns="False" Margin="8,11,10,78"  
  ItemsSource="{Binding}" Name="CusGrid">  
  <grid:DataGrid.Columns>  
  <grid:DataGridTextColumn Binding="{Binding Path=CustomerID}"  
  Header="Customer ID" />  
  </grid:DataGrid.Columns>  
  ....other columns goes here  
  </grid:DataGrid>  
7. In your Window1.cs file, populate your grid with resulset
protected void GridLoad()  
 {  
  SqlConnection conn = new SqlConnection(your_connection_string);  
  SqlCommand cmd = new SqlCommand("select * from customers",conn);  
  DataSet ds = new DataSet();  
  SqlDataAdapter da = new SqlDataAdapter(cmd);  
  da.Fill(ds);  
  CusGrid.DataContext = ds.Tables[0];  
 }
8. Run your application.
That's It!

Comments

Donate

Popular Posts From This Blog

WPF CRUD Application Using DataGrid, MVVM Pattern, Entity Framework, And C#.NET

TypeScript Error Or Bug: The term 'tsc' is not recognized as the name of a cmdlet, function, script file, or operable program.

Invalid nested tag div found, expected closing tag input