I am converting a VBA project into C# and WPF.
I'm affraid that I just do not understand BINDING.
NOTE: I am using LINQ to Entities to access data from an SQL Database.
My problem is as follows:
(This is just a small fictitious example. In reality these tables have many fields)
1. I have a table called CLIENT which has 2 fields:
(ClientCD and ClientCountryCD)
2. I also have a table called COUNTRY which has 2 fields:
(CountryCD and CountryName)
3. CLIENT is related to COUNTRY via the ClientCountryCD.
4. In XAML I have a row which contains:
a) TextBox to display ClientCD - followed by
b) ComboBox to display ClientCountryCD from CLIENT table and
select CountryCD from the COUNTRY table.
c) TextBox (disabled) to display CountryName from the COUNTRY table
that reflects the ClientCountryCD both initially and when another
is selected from the ComboBox.
How do I perform the required binding?
What I have below is clearly incorrect.
<Grid DataContext="{StaticResource tblClientsViewSource}"
Margin="20,200,0,0"
HorizontalAlignment="Left"
Name="grid1"
VerticalAlignment="Top">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<Label Content="Client:"
HorizontalAlignment="Left"
VerticalAlignment="Center" />
<TextBox Grid.Column="1"
Height="23"
HorizontalAlignment="Left"
Name="cli_ClientTextBox"
Text="{Binding Path=cli_Client, Mode=TwoWay, ValidatesOnExceptions=true, NotifyOnValidationError=true}"
VerticalAlignment="Center" Width="120" />
<Label Content="Country:"
Grid.Column="2"
HorizontalAlignment="Left"
Margin="3"
VerticalAlignment="Center" />
<ComboBox DisplayMemberPath="cli_Country"
Grid.Column="3"
Height="23"
HorizontalAlignment="Left"
ItemsSource="{Binding}"
Name="cli_CountryComboBox"
VerticalAlignment="Center"
Width="120" />
<Label Content="Name:"
Grid.Column="4"
HorizontalAlignment="Left"
VerticalAlignment="Center" />
<TextBox DataContext="{StaticResource tblCountriesViewSource}"
Grid.Column="5"
Height="23"
HorizontalAlignment="Left"
Name="cnt_NameTextBox"
Text="{Binding Path=cnt_Name, Mode=TwoWay, ValidatesOnExceptions=true, NotifyOnValidationError=true}"
VerticalAlignment="Center"
Width="120" />
</Grid>