Click here to Skip to main content
15,914,416 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i have a list of 3 students with details in it.i want to bind the list to datagrid.how can i do that.Following is my code behind and xaml.please give me corrections:



C#
public partial class MainWindow : Window
   {



       private List<student> _personaldetails = new List<student>();

       public MainWindow()
       {
           InitializeComponent();
           _personaldetails.Add(new student { name = "qqq", id = "qqq", address = "qqq" });
           _personaldetails.Add(new student { name = "www", id = "www", address = "www" });
           _personaldetails.Add(new student { name = "eee", id = "eee", address = "eee" });

}






xaml:



<datagrid autogeneratecolumns="True" height="311" horizontalalignment="Left" margin="281,0,0,0" name="dataGrid1" verticalalignment="Top" width="222" itemssource="{Binding _personaldetails}">
<datagrid.columns>
<datagridtextcolumn header="Name" width="75" canuserresize="False" canuserreorder="False" isreadonly="True">
<datagridtextcolumn header="Id" width="75" canuserresize="False" canuserreorder="False" isreadonly="True">
<datagridtextcolumn header="Address" width="75" canuserresize="False" canuserreorder="False" isreadonly="True">

Posted

1 solution

Bind the collection to the datagrid

HTML
ItemsSource="{Binding __personaldetails}"


Get book on WPF and work through the examples, download some of the beginner articles and take a look at them.
 
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