I'm trying to create this ContentView where it will get different columns from the database based on the ClassID. I'm having a problem when it comes to displaying the correct data. I'm not sure if my approach is the right way? Can I use my variable cType to change the binding of the label inside the ViewCell
How I called the ContentView
<local:AutoCompleteEntry
x:Name="vBrand"
ClassId="brand"
/>
<local:AutoCompleteEntry
x:Name="vPart"
ClassId="part"
/>
XAML
<StackLayout Orientation="Vertical" BackgroundColor="AliceBlue">
<Entry TextChanged="searchBar_TextChanged"
BackgroundColor="#f9f9f9"
TextColor="#FF464859"
Unfocused="searchBar_Unfocused"
FontSize="16" PlaceholderColor="#646b7a"
x:Name="searchBar"
Placeholder="Type here..."/>
<ListView x:Name="lvw" IsVisible="False"
CachingStrategy="RecycleElement"
BackgroundColor="White"
ItemTapped="lvw_ItemTapped">
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<Frame>
<StackLayout BackgroundColor="White">
<Label Text="{Binding ctype}" FontSize="16" TextColor="Black"/>
</StackLayout>
</Frame>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
</StackLayout>
CODE
ObservableCollection<Item> collection;
SqliteDB<Item> dbItem = new SqliteDB<Item>(unique.dbPath);
String ctype="";
private async Task initLvw()
{
ctype = ClassId;
switch (ClassId)
{
case "brand":
collection = await dbItem.ReadData(e=>e.brand.Contains(searchBar.Text));
lvw.ItemsSource = collection.Select(i => i.brand);
break;
case "part":
collection = await dbItem.ReadData(e => e.partno.Contains(searchBar.Text));
lvw.ItemsSource = collection.Select(i => i.partno);
break;
case "plgrp":
collection = await dbItem.ReadData(e => e.plgrp.Contains(searchBar.Text));
lvw.ItemsSource = collection.Select(i => i.plgrp);
break;
case "itemname":
collection = await dbItem.ReadData(e => e.itemname.Contains(searchBar.Text));
lvw.ItemsSource = collection.Select(i => i.itemname);
break;
}
lvw.EndRefresh();
}