Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6069709
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T09:51:05+00:00 2026-05-23T09:51:05+00:00

in a c# wpf application, Im loading a treeView from a list, it has

  • 0

in a c# wpf application, Im loading a treeView from a list, it has a delete, edit, and add button used with information saved in a list from a textFile, it also has a update button which when clicked it clears the treeView and then reloads the textFile info into the list and then the lists into the treeView however whenever i click the update its crashes my file when it hits: treeView1.Items.Clear(); all the variables prior to the .Clear() lines at the start are lists, also the there are more if statements similar to this one if(i == 0) i just took them out cause they all work the same. Thanks

here is the event code for the updated button

private void buttonUpdate_Click(object sender, RoutedEventArgs e)
{

    name.Clear();
    description.Clear();
    dateStart.Clear();
    dateDue.Clear();
    status.Clear();
    priority.Clear();
    details.Clear();

    using (StreamReader sr = new StreamReader("TaskList.txt"))
    {
        int i = 0;
        while (!sr.EndOfStream)
        {
            //if its on the first line of a task
            if (i == 0)
            {
                name.Add(sr.ReadLine());
                ++i;
            }
            else if (i == 1)
            {
                description.Add(sr.ReadLine());
                ++i;
            }
            else if (i == 2)
            {
                dateStart.Add(sr.ReadLine());
                ++i;
            }
            else
            {
                details.Add(sr.ReadLine());
                i = 0;
            }
        }

        treeView1.Items.Clear();

        for (int j = 0; j < name.Count; ++j)
        {
            TreeViewItem taskTree = new TreeViewItem();
            taskTree.Tag = name[j];
            taskTree.Header = name[j];
            taskTree.Items.Add(description[j]);
            taskTree.Items.Add(dateStart[j]);
            taskTree.Items.Add(dateDue[j]);
            taskTree.Items.Add(status[j]);
            treeView1.Items.Add(taskTree);
        }
        sr.Close();
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T09:51:06+00:00Added an answer on May 23, 2026 at 9:51 am

    After clearing the treeview, SelectedItem is null.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a wpf c# application, that loads tasks to a treeView from a
Has anyone used CSLA in an application that has a WPF front end and
We have a WPF application that is loading a usercontrol at runtime from the
The Splashscreen/Loading-Window in my WPF application is set to Topmost=True . Now this windows
After developing a WPF application without Source Control, I decided to add the solution
I have a WPF application which has a DirectX component within it. This component
In my wpf application i am playing videos from the mms server. These video
I have this WPF application using NHibernate and lazy data loading. I also use
Recently our WPF/Entity Framework 4.0 application has become unstable after we began using backgroundworkers
I understand that there are problems regarding running a WPF application from a console

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.