I have two ListViews that I need to use LINQ to SQL (C #, WPF project) in a search field. When typing in the textbox field the KeyDown event will populate the first ListView (1), as the second has a column that is the Primary Key of the first, I need in that second ListView (2) to look for the Primary Key populated in the first ListView 1). It's possible?
Detail: In both lists variables are strings but have different values. For example, in ListiView (1) you search for a Description and in the ListView (2) a Primary Key that are numbers (although it is a string) that is in the ListView (1) as well.
Understand: DataBases_1 Population ListView_1 DataBases_2 Populate ListView_2
DataBases_1
Codigo(string_PK) | Descricao (string)
101 | Uva
202 | Maca
303 | Melao
404 | Salada Mista
505 | Morango
DataBases_2
Nome | Codigo(string_PK)
Joao | 404
Maria | 404
Paulo | 505
Felipe | 101
Renata | 202
Search Method of First ListView (1) - KeyDown Event:
using (DataClassesDataContext oDB = DataClassesDataContext())
{
var busca = from p in oDB.DataBases where p.Descricao.Contains(txtPesquisa.Text) orderby p.Codigo descending select p;
listView_1.ItemsSource = busca.ToList();
listView_2.ItemsSource = ??????? ---> //Popular com base na lista encontrada pelo ListView_1 (var busca)
}
XMAL:
<ListView x:Name="listView_1" Margin="34,345,618,51" ItemsSource="{Binding}" ScrollViewer.CanContentScroll="True" SelectionMode="Extended"><ListView.View> <GridView>
<GridViewColumn Header="Código" Width="Auto" DisplayMemberBinding="{Binding Codigo/>
<GridViewColumn Header="Descricao" Width="Auto" DisplayMemberBinding="{Binding Descricao}"/>
</GridView>
</ListView.View>
</ListView>
<ListView x:Name="listView_2" Margin="1050,345,72,51" ItemsSource="{Binding}" ScrollViewer.CanContentScroll="True" SelectionMode="Extended">
<ListView.View>
<GridView>
<GridViewColumn Header="Nome" Width="Auto" DisplayMemberBinding="{Binding Nome}"/>
<GridViewColumn Header="Código" Width="Auto" DisplayMemberBinding="{Binding Codigo}"/>
</GridView>
</ListView.View>
</ListView>