Hello:
I am very new to Visual Studio 2008 C#. I would like to populate a TreeView at run time and when a specific node/child is clicked it will open a form assigned to that node/child. Is there a sample code that I can look at that does this?
Loading
Kirtan PatelPosted Feb 15, 2010, 12:40 PM
private void treeView1_NodeMouseClick(object sender, TreeNodeMouseClickEventArgs e)
{
if (e.Node.Name == "Node0")
{
//Open Form 1
Form1 f1 = new Form1();
f1.Show();
}
else if (e.Node.Name == "Node1")
{
//Open form 2
Form1 f2 = new Form2();
f2.Show();
}
else
{
//Open Some other Form
}
}
Santosh Kumar SinghPosted Dec 9, 2014, 1:28 AM
Shaik AliPosted Feb 23, 2010, 12:48 PM
theLizardPosted Feb 18, 2010, 5:20 PM
Good stuff, there is always a better way but some times you cannot see the forest for the trees.
The solution is a good one and I don't think I would have developed a solution like it but I think that would have been because I did not have a need to so now I have learned.
About the NameSpace, unless you will have multiple name spaces (I still don't have a need to look into it, but) you could have a static variable declared globally
static string theNameSpace = "ICEPack";
Form oFormToOpen = (Form)oAssembly.CreateInstance(theNameSpace + "." + e.Node.Tag);
This of cause may be a lazy way around it.
look forward to seeing the flow chart.
GustavoPosted Feb 17, 2010, 8:57 PM
Thanks for the info... I will look (evaluate) at moving to C++Builder 2010. I guess they come out with a new version every August, so I might wait till August to get the 2011 version. meanwhile I will develop with VS C# 2k8. I can get the basics ready.
The flow chart is not propriatery or nothing. Its my own design and I will show you one part of it .
BTW: I was able to resolve the issue I had with the TreeView being used as a menu and on click to open the related form. Basically its 5 lines of code. Code below, just in case you are curious.
Assembly oAssembly = Assembly.GetEntryAssembly();
if (e.Node.Tag != null)
{
Form oFormToOpen = (Form)oAssembly.CreateInstance("ICEPack" + "." + e.Node.Tag);
oFormToOpen.MdiParent = this;
oFormToOpen.Show();
}
Now I need to find a way to get the NameSpace of the main program systematically so I dont have to hard code it ("ICEPack").
theLizardPosted Feb 17, 2010, 8:43 PM
No, not VS 2008, I don't much like it but that is only my opinion, I started c++ with ver 5, I now use 2009, if you can get hold of an academic version it would not be that expensive and will give you greater flexibility but then I am prettty biased even though I use C# in website design.
To give you an idea of how insecure C# is i had to resort to writting a c++ dll AND a C# dll (c# dll is obfuscated) called as unmanaged code from code behind in a website just to ensure that algorithms for critical functions are made more difficult to reverse engineer if anyone ever got hold of the compiled website dll's
Google "Reflector.exe" you will be amazed at what it does with C# exe's and dll's whoever designed C# did not design it to deal with security of reverse engineering.
Yes I am really interested in seeing a flow chart, I don't need you divulge any propriety info though.
I look forward to seeing it.
GustavoPosted Feb 17, 2010, 4:32 PM
Interesting what you said about C#. I am still at the beginning stage... you think I should move to Visual Studio C++ ? I have played with C++Builder (ver 5) many years ago and I liked it a lot better then the Microsoft Visual Studio, at that time. However, I have a copy of VS 2008 Pro now... I hate to shell out the $$ for the C++Builder. Maybe If I get the project moving again, I will spend the money and get the new C++Builder.
If you are really interested in a flow chart... I will try to put one together for one of the selections. then you can multiply it by all the main tables I have. (Will take me a while to put it together).
theLizardPosted Feb 17, 2010, 4:15 PM
To start with you are not an old fart, I am 30 + then some, that makes me the old fart :) anyway i am really curious, you say you will have about a hundred forms per division, but I cant imaging needing that many, I would love to see a flow chart of some sort to get an idea of the forms for one division say manufacturing.
Something else, you said that you are doing this for fun and / or profit, if for fun then it would be ok to do it in C#, BUT if you intend to sell your final product C# is NOT the choice I would make simply because it can very easily be reverse engineered without obfuscation which I don't like especially if you have external C# dll's also obfuscated, turns your application into a spaghetti bowl junction.
Apart from what I mentioned you are also at the mercy of .NET and it's overheads.
For something of this nature I would do it in C++ Builder where you could produce a single exe if need be, much better way to go...
And I have also written in languages I would say that most likely no one on this forum would ever have herd of before so we have something in common.
GustavoPosted Feb 17, 2010, 10:53 AM
Thanks for your input. I have some ideas but others input is good. I might find a better way to do this project with others input. Your criticism is accepted. Even if I am stubborn at times.
Let me explain my project a bit: I have been a software designer/programmer for many years (I'm am old fart...30+ years). I have done projects in other databases and programming languages, some that some might have not heard of. I want to take all my knowledge and re-write a package with new/modern technology.
The package will have 4 main modules (1. Accounting, 2. Manufacturing, 3. Distribution, 4. System). So that is about 100 forms per module. I want to make everything parameter (table) driven. I have seem so many packages that do not validate to good (just my opinion). I would have everything validated and mostly by tables. Maybe I am over validating things, but I have done it for a few companies and it worked out super well. Must of the tables will only be needed for the initial setup and then rarely modified or enhanced. Most of the packages that I have done in the past have had around 2,000-2,400 forms for the full system. With the 'tab' function this will allow me to get it down to around 400. I can go on and on...LOL.
I appreciate your input and look forward in looking at your post example. Keep on giving me input. (As Johnny 5 use to say: "I need INPUT').
theLizardPosted Feb 17, 2010, 12:22 AM
It seems a lot of forms for what you you want to do, I have already written a similar type of application in C++ (MDI) using a tree view (see post here) and it is not so much a strain on the system as it may be on your users.
And there is always a better way of doing things but without knowing what all those forms do it is very hard for anyone to work out which would be the best way.
By the way, I am not being critical at what you are doing just never come across an application with so many forms.
GustavoPosted Feb 16, 2010, 3:26 PM
Yes, I am for real. I am not an Avatar.
What I am tring to do is to use the TreeView as a menu selector. There is up to about 400+ application forms that I will be writting.
If you think this is 'not real', do you have some other idea on how I can do this. I want them to select something from a menu and be able to run any of the 400+ forms.
I am writting an application system for Accounting, Manufacturing and Distribution from scratch (For fun and possibly for profit). I would like to have everything run inside a MDI. If you think this is not a good idea, please let me know of another alternative. I have written software application packaged in the past in other languages and it was not so hard or a strain on the system.
theLizardPosted Feb 16, 2010, 3:35 AM
What are you doing with 403 forms?
Why can't you have just one form and do what it needs to do for the node that is clicked a hell of a lot easier to manage.
I would hate to see your code to manage 403 separate forms.
GustavoPosted Feb 15, 2010, 11:56 PM
I just looked and have an exact count. I will be having 403 forms at this point.
Let me try to explain again what I am trying to do. Hopefully a bit cleared this time.
I will read the database table at run time and load up the TreeView. The TreeView will be multi-level.
When the user chicks the TreeView, I wouild like to pick up the e.Node.Name at treeView1_NodeMouseClick... The SHow the Form of the same name.
Diptimaya PatraPosted Feb 15, 2010, 11:46 PM
Could you please tell me how many forms do you have or you are displaying the node details in a single form? :)
Thanks
Diptimaya Patra
GustavoPosted Feb 15, 2010, 2:36 PM
Thanks... I was hoping for something simpler, but this will do for now. This will lead me to playing with this solution.
Reason I say 'simpler' is because I will be populating the TreeView with 200-300 items from a database. I hate to hard code 200-300 if/else statements.
It would be nice if there is something like the following to do what I need.
FormToShow f1 = e.Node.Name;
f1.Show();