本文介绍了如何根据选择将列表绑定到数据网格并查看内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有3个学生的列表,其中包含详细信息。我想将列表绑定到datagrid。我可以这样做。以下是我的代码,xaml.please给我更正:







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:



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 =Trueheight =311horizo​​ntalalignment = leftmargin =281,0,0,0name =dataGrid1verticalalignment =Topwidth =222itemssource ={Binding _personaldetails}>

< datagrid .columns>

< datagridtextcolumn header =Namewidth =75canuserresize =Falsecanuserreorder =Falseisreadonly =True>

< ; datagridtextcolumn header =Idwidth =75canuserresize =Falsecanuserreorder =Falseisreadonly =True>

< datagridtextcolumn header =Addresswidth =75canuserresize =Falsecanuserreorder =Falseisreadonly =True>



}






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">

推荐答案

ItemsSource="{Binding __personaldetails}"





获取WPF书籍并完成示例,下载一些初学者文章并看看它们。



Get book on WPF and work through the examples, download some of the beginner articles and take a look at them.


这篇关于如何根据选择将列表绑定到数据网格并查看内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-22 15:56