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 3321460
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T23:03:55+00:00 2026-05-17T23:03:55+00:00

I’m writing an application where I fill out a TreeView with the schema of

  • 0

I’m writing an application where I fill out a TreeView with the schema of a database. I do so by iterating over each table name and type in GetSchema. Then, depending on the DataType and name, I select the parent Node into which I want to add a new item. Sometimes that item does not exist in the treenode (depending on user settings certain tables may or may not have been added as nodes of the treeview), which is fine, in that case I want either:

A) An exception to be thrown so I KNOW that it failed to find the node as asked for. Or B) null to be returned for the failed accessor.

A (highly modified) snippet of my code:

TreeNode parent = null;
if( tableName.StartsWith("prefix") )
{
    parent = tablesNode.Nodes["Node Name which might not exist"];
}

if (parent == null && IgnorePrefixedTables)
{
    continue;
}
else if (parent == null)
{
    throw Exception();
}
....<More Code For Filling Out that node>...

The problem is, that when I step through this code (or rather, the real code) when I reach tablesNode.Nodes[“Node Name which might not exist”] for a node name that doesn’t exist I am unable to catch the exception because none is thrown. If I step into or over that line of code the whole method returns me up to the highest level (my form immediately gets shown and the UI is partially complete). What’s up with that?

[EDIT]

Here’s a VERY simplified version of my problem:

namespace TestZone
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            treeView1.Nodes.Add("Hello", "Hello");
            var x = treeView1.Nodes["Hello"];
            x.Nodes.Add("World-PL", "Swiat");
            x.Nodes.Add("World-EN", "World");
            var y = treeView1.Nodes["World-EN"];
            MessageBox.Show(y.Text);
            y = treeView1.Nodes["World-SP"];
            MessageBox.Show(y.Text);
            y = treeView1.Nodes["World-PL"];
            MessageBox.Show(y.Text);
        }
    }
}

The code relies on textBox1 being on Form1. (P.S. PL is Polish). Apparently treeView1 can’t find World-EN either which makes me think I’m really not understanding how treeView works. The first MessageBox never gets shown and breakpoints on y = treeView1.Nodes[“World-SP”]; fail to break (since that line of code never gets called).

  • 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-17T23:03:56+00:00Added an answer on May 17, 2026 at 11:03 pm

    Avoid using exceptions to control program flow. Use the TreeViewCollection.IndexOfKey() method.

    There’s a strange bug on a 64-bit operating system when an exception is raised in the form’s OnLoad() method or Load event and a debugger is attached. It is swallowed without notification. Sounds like a match. Workaround is to set the Platform target to x86.

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

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
Basically, what I'm trying to create is a page of div tags, each has
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I am writing an app with both english and french support. The app requests
I have a reasonable size flat file database of text documents mostly saved in
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but
For some reason, after submitting a string like this Jack’s Spindle from a text

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.