我有来自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();
您可以使用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>