When my DataGrid populates on the TreeView's SelectedItemChanged event it finds the objects and creates the rows accordingly but the rows populate with no text or are just blank. So I know it is finding my objects but it is not displaying them properly. Does anyone see where I made an error or suggest any changes or fixes? Thank you in advance!
Here is the CSharp code that is setting the DataGrid's ItemsSource (I am using .dbml and LINQ with Lambda expressions):
dgSystemSettings.ItemsSource = (tvSystemConfiguration.SelectedItem as SYSTEM_SETTINGS_GROUP)
.SYSTEM_SETTINGS_NAMEs
.Join(ssdc.SYSTEM_SETTINGS_VALUEs, x => x.SSN_ID,
y => y.SSV_SSN_ID,
(x, y) => new { SYSTEM_SETTINGS_NAME = x,
SYSTEM_SETTINGS_VALUE = y });
And here is the .xaml:
<DataGrid Name="dgSystemSettings"
AutoGenerateColumns="False"
Height="447" Width="513"
DockPanel.Dock="Right"
ItemsSource="{Binding}"
VerticalAlignment="Top"
Margin="10,10,0,0">
<DataGrid.Columns>
<DataGridTextColumn x:Name="colDisplay开发者_JAVA百科Name"
Header="Name"
Binding="{Binding SSN_DISPLAY_NAME}"></DataGridTextColumn>
<DataGridTextColumn x:Name="colValue"
Header="Value"
Binding="{Binding SSV_VALUE}"></DataGridTextColumn>
</DataGrid.Columns>
</DataGrid>
SSN_DISPLAY_NAME is a column in SYSTEM_SETTINGS_NAMES SSV_VALUE is a column in SYSTEM_SETTINGS_VALUES
I joined the tables in my lambda expression so I can display only these two columns in my DataGrid.
I believe that you may want to change the text of the DataGridTextColumn to the following:
<DataGrid Name="dgSystemSettings" AutoGenerateColumns="False" Height="447" Width="513" DockPanel.Dock="Right" ItemsSource="{Binding}" VerticalAlignment="Top" Margin="10,10,0,0">
<DataGrid.Columns>
<DataGridTextColumn x:Name="colDisplayName" Header="Name" Binding="{Binding SYSTEM_SETTING_NAME.SSN_DISPLAY_NAME}"></DataGridTextColumn>
<DataGridTextColumn x:Name="colValue" Header="Value" Binding="{Binding SYSTEM_SETTING_VALUE.SSV_VALUE}"></DataGridTextColumn>
</DataGrid.Columns>
</DataGrid>
Since your rows were populating the correct number of items, I figured it had to be a binding issue. When you set the ItemsSource of the DataGrid, it looks for a View Collection of the object. Your data was all there, you just needed to include the table names in the bindings. Each item in your code contained two objects for the tables and the tables contained the properties you were looking for.
I had AutoGenerateColumns
set to False
in my xaml. Setting it to True
fixed this.
精彩评论