I have the following tables:
Company {CompanyID, CompanyName}
Deal {CompanyID, Value}
And I have a list:
<ListBox Name="Deals" Height="100" Width="420" Margin="0,20,0,0" HorizontalAlignment="Left" VerticalAlignment="Top" Visibility="Visible" IsSynchronizedWithCurrentItem="True" ItemsSource="{Binding}" SelectionChanged="Deals_SelectionChanged"> <ListBox.ItemTemplate> <DataTemplate> <StackPanel Orientation="Horizontal"> <TextBlock Text="{Binding companyRowByBuyFromCompanyFK.CompanyName}" FontWeight="Bold" /> <TextBlock Text=" -> TGS -> " /> <TextBlock Text="{Binding BuyFrom}" FontWeight="Bold" /> </StackPanel> </DataTemplate> </ListBox.ItemTemplate> </ListBox>
As you can see, I want to display company_name, not the identifier, which is the foreign key. The relationship "companyRowByBuyFromCompanyFK" exists, as in the Deals application. I can access the companyRowByBuyFromCompanyFK property in the "Transactions" line, and also access the CompanyName property of this line.
Is the reason why this does not work because the XAML binding uses the [] indexer? Instead of properties in CompanyRows in my DataTable?
At the moment im, getting values ββlike
- β TGS β 3
- β TGS β 4
Edit Update binding errors
System.Windows.Data error: 39: Binding pathion error: 'CompanyRowByBuyFromCompanyFK' property not found on 'object' 'DataRowView' (HashCode = 30295189) '. BindingExpression: Path = companyRowByBuyFromCompanyFK.CompanyName; DataItem = 'DataRowView' (HashCode = 30295189); target element "TextBlock" (Name = ''); the target property is βTextβ (type βStringβ)
It does not seem to convert the DataRowView element to a list of providers
What would be the best way to accomplish this?
Make a converter to convert foreign keys using the table referenced as a user parameter.
Create a table view for each table? This would be long because I have a fairly large number of tables with foreign keys.
source share