Click here to Skip to main content
15,890,825 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i am trying to display the data on a datagrid in wpf. but i don't know how to add columns in the datagrid...can any one help me??
Posted
Comments
Pheonyx 5-Nov-13 3:16am    
Well what have you tried? Have you looked up how to use the WPF DataGrid?
Member 9871483 5-Nov-13 3:26am    
<datagrid horizontalalignment="Left" margin="108,42,0,0" verticalalignment="Top" height="273" width="398" name="dtgridClass" selectionchanged="dtgridClass_SelectionChanged">
<datagrid.columns>
<datagridtextcolumn binding="{Binding FirstName}" width="100" header="First Name">
<datagridtextcolumn binding="{Binding LastName}" width="100" header="Last Name">
<datagridtextcolumn binding="{Binding Salary}" width="100" header="Salary">


but there is an error occured which says that "datagridtextcolumn"is not supported by WPF..
Alexander Dymshyts 5-Nov-13 6:01am    
where is the code?

Set the itemsource of the datagrid
 
Share this answer
 
Basic Example to bind dataGrid in WPF :Datagrid name is dgDisplay
C#
manually adding columns and one row
DataTable dt;
 dt = new System.Data.DataTable();
               dt.Columns.Add("First Name");
               dt.Columns.Add("Last Name");
               dt.Columns.Add("Mobile Number");
               dt.Columns.Add("Email Address");
               dt.Columns.Add("Company");
               dt.Columns.Add("Web Page");
               dt.Columns.Add("Notes");
               dt.Rows.Add(new object[] { "hari","Krishna", "9000000000", "haripobbati@gmail.com", "EMC",www.EMC.co.in,"Software Engineer" });                 
               
               dgDisplay.ItemsSource = dt.DefaultView;

(or) if you have dataset data fetched from datatbase then you can directly set DataGird ItemsSource property as below

C#
dgDisplay=ds.Tables[0];
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900