找不到Datagrid Wpf行 [英] Unable to find Row of Datagrid Wpf
本文介绍了找不到Datagrid Wpf行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
Xaml:
<DataGrid
Name="dgIssuedItemsBatchWise"
AutoGenerateColumns="False"
CanUserAddRows="False"
Loaded="dgIssuedItemsBatchWise_Loaded"
LoadingRow="dgIssuedItemsBatchWise_LoadingRow"
LoadingRowDetails="dgIssuedItemsBatchWise_LoadingRowDetails"
>
<DataGrid.CellStyle>
<Style TargetType="DataGridCell">
</Style>
</DataGrid.CellStyle>
<DataGrid.RowHeaderTemplate>
<DataTemplate>
<Expander
Expanded="Expander_Expanded"
Collapsed="Expander_Collapsed">
</Expander>
</DataTemplate>
</DataGrid.RowHeaderTemplate>
<DataGrid.Columns>
<DataGridCheckBoxColumn
Width="100"
Binding="{Binding IsIndentIssue,UpdateSourceTrigger=PropertyChanged}"
>
<DataGridCheckBoxColumn.Header >
<TextBlock
FontWeight="Bold"
Text="Is Selected"
/>
</DataGridCheckBoxColumn.Header>
</DataGridCheckBoxColumn>
<!--<DataGridCheckBoxColumn Width="100" Header="Is Selected" Binding="{Binding IsIndentIssue}" />-->
<DataGridTextColumn
Width="150"
IsReadOnly="True"
Header="Item Name"
FontWeight="Bold"
Binding="{Binding ItemName}"
/>
<DataGridTextColumn
Width="100"
IsReadOnly="True"
Header="Item Code"
FontWeight="Bold"
Binding="{Binding ItemCode}"
/>
<DataGridTextColumn
Width="100"
IsReadOnly="True"
x:Name="reqQuantity"
Header="Required Quantity"
FontWeight="Bold"
Binding="{Binding Quantity}" />
<DataGridTextColumn
Width="100"
IsReadOnly="True"
x:Name="issQty"
Header="Issued Quantity"
FontWeight="Bold"
Binding="{Binding IssueQuantity}"
/>
</DataGrid.Columns>
<DataGrid.RowDetailsTemplate>
<DataTemplate>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" ></RowDefinition>
<RowDefinition Height="Auto"></RowDefinition>
</Grid.RowDefinitions>
<DataGrid Grid.Row="0"
Height="Auto"
Padding="10,10,10,10"
Width="1320"
Grid.ColumnSpan="5"
ItemsSource="{Binding BatchWiseItems,UpdateSourceTrigger=PropertyChanged}"
x:Name="dgIssuedItemsBatchDetails"
AutoGenerateColumns="False"
HorizontalAlignment="Stretch"
VerticalAlignment="Center"
CanUserAddRows="False"
>
<DataGrid.Columns>
<!--<DataGridTextColumn Width="440" >
<DataGridTextColumn.Header>
<CheckBox
HorizontalAlignment="Center"
VerticalAlignment="Center" />
</DataGridTextColumn.Header>
</DataGridTextColumn>-->
<DataGridCheckBoxColumn
Width="100"
Binding="{Binding IsItemIssued,UpdateSourceTrigger=PropertyChanged}">
<DataGridCheckBoxColumn.Header >
<TextBlock
FontWeight="Bold"
Text="Is Issued"
/>
</DataGridCheckBoxColumn.Header>
</DataGridCheckBoxColumn>
<!--<DataGridCheckBoxColumn Width="100" Header="Is Issued" Binding="{Binding IsIndentIssue}" />-->
<DataGridTextColumn
Binding="{Binding BatchNo}"
Width="440" >
<DataGridTextColumn.Header>
<TextBlock
FontWeight="Bold"
Text="Batch No"
/>
</DataGridTextColumn.Header>
</DataGridTextColumn>
<DataGridTextColumn
Binding="{Binding Quantity}"
Width="440" >
<DataGridTextColumn.Header>
<TextBlock
FontWeight="Bold"
Text="Quantity"
/>
</DataGridTextColumn.Header>
</DataGridTextColumn>
</DataGrid.Columns>
</DataGrid>
<!--<TextBox Grid.Row="1" HorizontalAlignment="Center" VerticalAlignment="Center" Width="200" ></TextBox>-->
</Grid>
</DataTemplate>
</DataGrid.RowDetailsTemplate>
</DataGrid>
我需要根据一些计算来更改行颜色。在GridView中,我们有 RowDataBound
事件,但在DataGrid中,有人建议我使用 DataGrid_LoadingRow
事件。我使用类似这样的事件
I need to change the row color based on some calculations. In GridView we have RowDataBound
event but in DataGrid someone suggest me to use DataGrid_LoadingRow
event.I use that event like
private void dgIssuedItemsBatchWise_LoadingRow(object sender, DataGridRowEventArgs e)
{
DataRowView item = e.Row.Item as DataRowView ;
if (item != null)
{
}
}
但是每次我得到null项时,有人建议我如何解决该问题或更改WPF DataGrid中的行颜色。
but every time i get item as a null.Someone suggest me how to solve that problem or change the row color in WPF DataGrid.
推荐答案
尝试
private void dgIssuedItemsBatchWise_LoadingRow(object sender,
DataGridRowEventArgs e)
{
DataRowView item = e.Row.DataContext as DataRowView ;
if (item != null)
{
}
}
更改
DataRowView item = e.Row.DataContext as DataRowView ;
而不是
DataRowView item = e.Row.Item as DataRowView ;
希望它对您有帮助
这篇关于找不到Datagrid Wpf行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文