如何将行添加到绑定的多列 DataGrid (Silverlight 4.0)
我将如何使用下面的代码将项目添加到 DataGrid
<sdk:DataGrid AutoGenerateColumns="False" Height="294" HorizontalAlignment="Left" Margin="63,27,0,0" Name="Assignments_datagrid" VerticalAlignment="Top" Width="533" IsReadOnly="True" SelectionChanged="Assignments_datagrid_SelectionChanged">
<sdk:DataGrid.Columns>
<sdk:DataGridTextColumn Header="Assignment Name" Binding="{Binding Assignment_Name}"/>
<sdk:DataGridTextColumn Header="Type" Binding="{Binding Type}"/>
<sdk:DataGridTextColumn Header="Due Date" Binding="{Binding Assignment_Due_Date}"/>
<sdk:DataGridTextColumn Header="Class Name" Binding="{Binding Course_Name}"/>
</sdk:DataGrid.Columns>
</sdk:DataGrid>
How would I go about adding items to the DataGrid with the code below
<sdk:DataGrid AutoGenerateColumns="False" Height="294" HorizontalAlignment="Left" Margin="63,27,0,0" Name="Assignments_datagrid" VerticalAlignment="Top" Width="533" IsReadOnly="True" SelectionChanged="Assignments_datagrid_SelectionChanged">
<sdk:DataGrid.Columns>
<sdk:DataGridTextColumn Header="Assignment Name" Binding="{Binding Assignment_Name}"/>
<sdk:DataGridTextColumn Header="Type" Binding="{Binding Type}"/>
<sdk:DataGridTextColumn Header="Due Date" Binding="{Binding Assignment_Due_Date}"/>
<sdk:DataGridTextColumn Header="Class Name" Binding="{Binding Course_Name}"/>
</sdk:DataGrid.Columns>
</sdk:DataGrid>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
嗯,我不确定您的问题是什么,但这是我的建议:
确保您的 dataGrid 的“CanUserAddRows”选项设置为“True”
那么底部就会有一条额外的线。
如果单击该行的行标题,则可以添加新行。这将向您的源集合添加一个新项目
!请注意,要使其正常工作,您必须确保源项的类具有不带参数的构造函数(在弄清楚这一点之前,我在“新行”内容方面遇到了一些麻烦)
,例如:
hmmm, I'm not sure about what your problem is but here is what I suggest :
make sure your dataGrid's "CanUserAddRows" option is set to "True"
then you have an extra line at the bottom.
If you click the rowHeader of that line, you can add a new line. This will add a new Item to your source collection
!! Be careful that for this to work, you have to make sure that the class of your source item has a constructor with no parameter (I had some trouble with the "new row" stuff before figuring this out)
e.g. :