I have first and second ListView, as shown in the image:
Example
I populated the first ListView, using this code
This is my Xaml Code
<listview x:name="ListBox_Category_Names" verticalalignment="Stretch" horizontalalignment="Left" xmlns:x="#unknown" Width="auto" Height="300" SelectionMode="Single" Grid.Column="0" Margin="0,0,10,0" ScrollViewer.HorizontalScrollBarVisibility="Auto" ScrollViewer.VerticalScrollBarVisibility="Auto" SelectionChanged="ListBox_Category_Names_SelectionChanged">
<listview.view>
<gridview>
<gridviewcolumn header="Category Name" displaymemberbinding="{Binding Category_Names}" width="280" />
<gridviewcolumn header="Amount " displaymemberbinding="{Binding Category_Amount, ConverterCulture=ig-NG, StringFormat=\{0:C\}}" width="130" />
</gridview>
</listview.view>
</listview>
<listview x:name="ListBox_Selected_Category" verticalalignment="Stretch" horizontalalignment="Stretch" xmlns:x="#unknown" Width="auto" Height="300" SelectionMode="Single" Grid.Column="1" Margin="10,0,0,0" ScrollViewer.HorizontalScrollBarVisibility="Auto" ScrollViewer.VerticalScrollBarVisibility="Auto" ItemsSource="{Binding SelectedItem, ElementName=ListBox_Category_Names}">
<listview.view>
<gridview>
<gridviewcolumn header="Category Name" displaymemberbinding="{Binding Category_Names}" width="250" />
<gridviewcolumn header="Amount">
<gridviewcolumn.celltemplate>
<datatemplate>
<textbox x:name="txtBox_amount" text="{Binding Category_Amount, ConverterCulture=ig-NG, StringFormat=\{0:C\}}" width="200" height="35" />
</datatemplate>
</gridviewcolumn.celltemplate>
</gridviewcolumn>
</gridview>
</listview.view>
</listview>
This is the Code thats Loads the First ListBox
ListBox_Category_Names.ItemsSource = CategoriesList.get_CategoryList();
Not MVVM
Now I'm stuck cause I need to bind the First ListView Selected Items to the Second ListView. Please, I really need help, been stuck with this for the past three (3) weeks. Thanks in advance.
What I have tried:
class CategoriesList
{
public string Category_Names { get; set; }
public double Category_Amount { get; set; }
public static List<categorieslist> get_CategoryList()
{
try
{
SQLiteConnection con = new SQLiteConnection(" Data Source=system.sqlite; Version=3; Compress=True; ");
con.Open();
string query = " SELECT category_id, category_name, amount FROM acc_income_category WHERE deleted = 0 ORDER BY category_name ASC ";
SQLiteCommand cmd = new SQLiteCommand(query, con);
SQLiteDataReader dr = cmd.ExecuteReader();
var categories = new List<categorieslist>();
while (dr.Read())
{
CategoriesList cl = new CategoriesList();
cl.Category_Names = dr.GetString(1);
cl.Category_Amount = dr.GetDouble(2);
categories.Add(cl);
}
con.Close();
return categories;
}
catch (Exception ex)
{
System.Windows.MessageBox.Show(ex.Message);
return null;
}
}
}