如何在silverlight 4中的datagrid中添加一个空行 [英] How to add a blank row in datagrid in silverlight 4

查看:59
本文介绍了如何在silverlight 4中的datagrid中添加一个空行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在Datagrid中动态添加行?因为我想添加没有详细信息的空行并从UI输入详细信息并保存。



我的数据网格 .xaml 代码在这里



提前致谢..

How to add rows dynamically in Datagrid? Because I want to add empty row without details and enter details from UI and save.

My Datagrid .xaml code goes here

Thanks in advance..

<UserControl x:Class="SilverlightApplication52.MainPage"

    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"

    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"

    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"

    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"

    mc:Ignorable="d"

    d:DesignHeight="300" d:DesignWidth="400" xmlns:sdk="http://schemas.microsoft.com/winfx/2006/xaml/presentation/sdk">

    <Grid x:Name="LayoutRoot" Background="White">
        <sdk:DataGrid AutoGenerateColumns="False" Height="176" HorizontalAlignment="Left" Margin="50,35,0,0" Name="DataGrid1" VerticalAlignment="Top" Width="312" >
            <sdk:DataGrid.Columns>
                <sdk:DataGridTextColumn x:Name="FirstName"

                                        Header="First Name"

                                        Binding="{Binding Path=FirstName}"

                                        IsReadOnly="False"

                                        Width="150"/>
                <sdk:DataGridTextColumn x:Name="LastName"

                                        Header="Last Name"

                                        Binding="{Binding Path=LastName}"

                                        IsReadOnly="False"

                                         Width="150"/>

                <sdk:DataGridTextColumn x:Name="Contactid"

                                            Header="Contact Id"

                                            Binding="{Binding Path= Contactid}"

                                            IsReadOnly="True"

                                            Width="150"

                                            Visibility="Collapsed"/>
            </sdk:DataGrid.Columns>
        </sdk:DataGrid>
        <Button Content="New" Height="23" HorizontalAlignment="Left" Margin="23,242,0,0" Name="btn_new" VerticalAlignment="Top" Width="75" Click="btn_new_Click" />
        <Button Content="Save" Height="23" HorizontalAlignment="Left" Margin="114,242,0,0" Name="btn_save" VerticalAlignment="Top" Width="75" Click="btn_save_Click" />
        <Button Content="Delete" Height="23" HorizontalAlignment="Left" Margin="207,242,0,0" Name="btn_delete" VerticalAlignment="Top" Width="75" Click="btn_delete_Click" />
    </Grid>
</UserControl>

推荐答案

在DataGrid中添加空行简单e为绑定到此Datagrid的Collection添加一个值。



例如,



如果你有将DataTable绑定到DataGrid,然后在To DataTable中添加新行将自动在Datagrid中添加新的空行。
To Add empty Row in DataGrid simple add one value to the Collection bound to this Datagrid.

for Example,

If you have bound a DataTable to your DataGrid then adding new Row in To DataTable will Automatically add new Empty Row in Datagrid.


一个类似的问题被提出这里 [ ^ ]。答案肯定会对你有所帮助。
A similar question was asked here[^]. The answers should surely help you.


这篇关于如何在silverlight 4中的datagrid中添加一个空行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆