Click here to Skip to main content
16,021,211 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have made a tree view and list view type SHOPPING CART in c#.Tree view shows different categories of books and when user clicks any of them all the books in that category are displayed in list view.But this is happening only for first node not after that.How do i do that? Plz Help

this is my code but the else if loop is never executed i dont know why?
C#
private void treeView1_NodeMouseDoubleClick(object sender, TreeNodeMouseClickEventArgs e)
{
    TreeNode newselect = e.Node;
    listView1.Items.Clear();
   // string[] arr = new string[2];

    if (e.Node.Text.ToString() == "Art, Design & Fashion")
    {

        listView1.Items.Clear();
        listView1.BeginUpdate();
        display();

        listView1.EndUpdate();
    }

}
void display()
{
    if (treeView1.SelectedNode.Text.ToString() == "Art, Design & Fashion")
    {
        ListViewItem item;
        string[] arr = new string[2];
        arr[0] = "Rugs & Carpets";
        arr[1] = "625";
        item = new ListViewItem(arr);
        listView1.Items.Add(item);
        arr[0] = "The Suit";
        arr[1] = "855";
        item = new ListViewItem(arr);
        listView1.Items.Add(item);
        arr[0] = "Style Mentors";
        arr[1] = "2696";
        item = new ListViewItem(arr);
        listView1.Items.Add(item);
        arr[0] = "Digital Photography";
        arr[1] = "2295";
        item = new ListViewItem(arr);
        listView1.Items.Add(item);
    }
    else if (treeView1.SelectedNode.Text.ToString() == "Entertainment")
    {
        listView1.Items.Clear();
        ListViewItem item;
        string[] arr = new string[2];
        arr[0] = "Rugs & Carpets";
        arr[1] = "625";
        item = new ListViewItem(arr);
        listView1.Items.Add(item);
        arr[0] = "The Suit";
        arr[1] = "855";
        item = new ListViewItem(arr);
        listView1.Items.Add(item);
        arr[0] = "Style Mentors";
        arr[1] = "2696";
        item = new ListViewItem(arr);
        listView1.Items.Add(item);
        arr[0] = "Digital Photography";
        arr[1] = "2295";
        item = new ListViewItem(arr);
        listView1.Items.Add(item);
    }
}
Posted
Updated 21-Mar-14 23:30pm
v2
Comments
BillWoodruff 22-Mar-14 11:10am    
You are only filling the ListView when the "Art, Design & Fashion" TreeNode is MouseDoubleClicked; that's why you are only seeing one result.
ZurdoDev 22-Mar-14 16:30pm    
Please post as solution. It was obvious which makes me think this is not the OPs code.
BillWoodruff 23-Mar-14 8:30am    
Thanks for the encouragement, Ryan, but it's my personal choice not to post such easy and obvious comments as "solutions."
Member 10377493 22-Mar-14 14:41pm    
thats correct thanks alot..i have corrected the mistake.
One more thing i want is that when user checks an item in the listview and presses add cart button it adds amount at the back end how can i do that for one as well as multiple items
BillWoodruff 23-Mar-14 8:32am    
I'd suggest you keep a running total in the front-end, and only update the DB in the back-end when the user has indicated by direct action that they have finished their current order. Ideally, you might see currently ordered items highlighted, or bolded, in some way to visually indicate their status.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900