What happens when you try to access winforms of TreeView by keywords and that there is no keyword?

I am writing an application where I populate a TreeView with a database schema. I do this by repeating each table name and type GetSchema. Then, depending on the type and name of the DataType, I select the parent Node to which I want to add a new element. Sometimes this element does not exist in treenode (depending on user settings, some tables may or may not be added as treeview nodes), which is good, in this case I want either:

A) An exception that needs to be thrown, so I KNOW that he could not find Node on request. Or B) null to return a failed accessory.

A (very modified) piece of 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>...

, (, ), tablesNode.Nodes [ "Node , " ] Node, , . , ( , ). ?

[EDIT]

:

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);
        }
    }
}

, textBox1 Form1. (P.S. PL ). -, treeView1 World-EN, , , TreeView. MessageBox y = treeView1.Nodes [ "World-SP" ]; ( ).

0
1

. TreeViewCollection.IndexOfKey().

64- , OnLoad() Load event, . . . x86.

+2

All Articles