0
私はWPFとエンティティフレームワークが初めてです。私のアプリケーションでは、非常に簡単なことをしたい、linqの結果をデータグリッドのクエリ結果に表示したい。ここで、ここで は私のクエリエンティティクエリ結果へのLinqへのデータグリッドコントロールのバインド
であるC#
private void applyButton_Click(object sender, RoutedEventArgs e)
{
string classFilter = classNameTextBox.Text;
var result = from c in partNumberContext.PartClasses
where c.chrPCName == classFilter
select c;
}
は私のXML trueにDataGrid内AutoGenerateColumnsを設定
<Window x:Class="Engenious.PartNumbers.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Part Details" Height="377" Width="607" Loaded="Window_Loaded">
<Window.Resources>
<CollectionViewSource x:Key="PartClassSource" />
</Window.Resources>
<Grid Height="346" Width="590">
<Label Content="Class Filter" Height="27" HorizontalAlignment="Left" Margin="75,26,0,0" Name="label1" VerticalAlignment="Top" Width="75" />
<TextBox Height="23" HorizontalAlignment="Right" Margin="0,28,141,0" Name="classNameTextBox" VerticalAlignment="Top" Width="194" />
<Button Content="Apply" Height="23" HorizontalAlignment="Right" Margin="0,27,26,0" Name="applyButton" VerticalAlignment="Top" Width="75" Click="applyButton_Click" />
<DataGrid AutoGenerateColumns="False" Height="263" HorizontalAlignment="Left" Margin="53,71,0,0" Name="dataGrid1" VerticalAlignment="Top" Width="479" />
</Grid>
:ここ
はコードです。 dataGrid1.AutoGenerateColumns = trueを設定するだけです。 – IamaC