当带文本框的text =显示id时,我想在单元格[1]中搜索。
我在DataGrid
中有相同的文字,但总是向我显示
not matching...
我使用以下代码:
for (int i = 0; i < datagrid_customer.Items.Count; i++)
{
if (Convert.ToString((datagrid_customer.SelectedCells[1].Column.GetCellContent(datagrid_customer.Items[i]) as TextBlock).Text) == txtcom.Text)
{
txt_f1.Text = Convert.ToString((datagrid_customer.SelectedCells[0].Column.GetCellContent(datagrid_customer.Items[i]) as TextBlock).Text);
}
else
{ txt_f1.Text = "Not Matching..."; }
}
什么问题
我该怎么办?
DataGrid
代码:
<DataGrid x:Name="datagrid_customer" HorizontalAlignment="Left" Height="322" VerticalAlignment="Top"
Margin="668,105,-667,0" Width="699" FlowDirection="RightToLeft" AutoGenerateColumns="False"
SelectionChanged="datagrid_customer_SelectionChanged" >
<DataGrid.Columns>
<DataGridTextColumn Header="کد محصول" Binding="{Binding MahID}">
<DataGridTextColumn.HeaderStyle>
<Style TargetType="{x:Type DataGridColumnHeader}">
<Setter Property="FontFamily" Value="B Yekan" />
<Setter Property="FontSize" Value="12" />
<Setter Property="HorizontalContentAlignment" Value="Center" />
</Style>
</DataGridTextColumn.HeaderStyle>
</DataGridTextColumn>
<DataGridTextColumn Header="نام محصول" Binding="{Binding MahName}">
<DataGridTextColumn.HeaderStyle>
<Style TargetType="{x:Type DataGridColumnHeader}">
<Setter Property="FontFamily" Value="B Yekan" />
<Setter Property="FontSize" Value="12" />
<Setter Property="HorizontalContentAlignment" Value="Center" />
</Style>
</DataGridTextColumn.HeaderStyle>
</DataGridTextColumn>
</DataGrid.Columns>
</DataGrid>