如何在wpf中创建DataGrid ReadOnly的第一行

问题描述 投票:-1回答:1

我有来自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();
wpf datagrid wpfdatagrid
1个回答
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>
© www.soinside.com 2019 - 2024. All rights reserved.