我在Datagrid中有一个数据库中的数据,我想编辑所有数据而无需第一行:
我只想将第一行用作只读记录,而我要编辑Jaama Rs
和BaNaam 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();
答案 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>