如何将行添加到绑定的多列 DataGrid (Silverlight 4.0)

发布于 2024-10-01 21:57:47 字数 821 浏览 0 评论 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

榆西 2024-10-08 21:57:48

嗯,我不确定您的问题是什么,但这是我的建议:

  • 确保您的 dataGrid 的“CanUserAddRows”选项设置为“True”

  • 那么底部就会有一条额外的线。

  • 如果单击该行的行标题,则可以添加新行。这将向您的源集合添加一个新项目

!请注意,要使其正常工作,您必须确保源项的类具有不带参数的构造函数(在弄清楚这一点之前,我在“新行”内容方面遇到了一些麻烦)

,例如:

    Class Item {
        public Assignment_Name { get; set; }
        ...

        public Item() { }

        ...

    }

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. :

    Class Item {
        public Assignment_Name { get; set; }
        ...

        public Item() { }

        ...

    }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文