如何在wpf

时间:2018-09-04 13:51:47

标签: wpf datagrid wpfdatagrid

我在Datagrid中有一个数据库中的数据,我想编辑所有数据而无需第一行:

Here you can see image by clicking this link

我只想将第一行用作只读记录,而我要编辑Jaama RsBaNaam Amount

以下是代码:

                        <DataGrid AutoGenerateColumns="False" Height="463"
                            HorizontalAlignment="Left" Margin="10,43,0,0" 
                             x:Name="gridcustomer" VerticalAlignment="Top" Width="911" IsReadOnly="True" ColumnWidth="*">
                            <DataGrid.Columns>
                                <DataGridTextColumn Binding="{Binding tblcustomer.Id}" Header="Code No" Width="60" 
                                    IsReadOnly="True"/>
                                <DataGridTextColumn Binding="{Binding Date}" Header="Date" 
                                    IsReadOnly="True"/>
                                <DataGridTextColumn Binding="{Binding tblcustomer.CustomerName}" Header="CustomerName"
                                    IsReadOnly="True"/>
                                <DataGridTemplateColumn Header="Jaama Rs">
                                    <DataGridTemplateColumn.CellTemplate>
                                        <DataTemplate>
                                            <TextBox x:Name="txteditcustomergridjamma" PreviewKeyDown="txteditcustomergridjamma_PreviewKeyDown"  PreviewTextInput="txteditcustomergridjamma_PreviewTextInput" Text="{Binding Jaama}"      />
                                        </DataTemplate>
                                    </DataGridTemplateColumn.CellTemplate>
                                </DataGridTemplateColumn>
                                <DataGridTemplateColumn Header="BaNaam Rs">
                                    <DataGridTemplateColumn.CellTemplate>
                                        <DataTemplate>
                                            <TextBox x:Name="txteditcustomergridbanaam" PreviewKeyDown="txteditcustomergridbanaam_PreviewKeyDown"  PreviewTextInput="txteditcustomergridbanaam_PreviewTextInput" Text="{Binding Banaam}"      />
                                        </DataTemplate>
                                    </DataGridTemplateColumn.CellTemplate>
                                </DataGridTemplateColumn>

                                <DataGridTextColumn Binding="{Binding Balence}" Header="Balence Rs" 
                                    IsReadOnly="True"/>
                                <DataGridTextColumn Binding="{Binding BalenceHistory}" Header="BalenceHistory" 
                                    IsReadOnly="True"/>
                            </DataGrid.Columns>
                        </DataGrid>
  

cs代码是

gridcustomer.ItemsSource=db.customerledger.toList();

1 个答案:

答案 0 :(得分:0)

您可以使用RowStyle禁用Balence == 0所在的行,例如:

<DataGrid AutoGenerateColumns="False" Height="463"
        HorizontalAlignment="Left" Margin="10,43,0,0" 
        x:Name="gridcustomer" VerticalAlignment="Top" Width="911" IsReadOnly="True" ColumnWidth="*">
    <DataGrid.RowStyle>
        <Style TargetType="DataGridRow">
            <Style.Triggers>
                <DataTrigger Binding="{Binding Balence}" Value="0">
                    <Setter Property="IsEnabled" Value="False" />
                </DataTrigger>
            </Style.Triggers>
        </Style>
    </DataGrid.RowStyle>
    <DataGrid.Columns>
        ...
    </DataGrid.Columns>
</DataGrid>