|
You want to create controls based on the selected treeview item? If so why not create the controls dynamically? That is , based on the value of the selected item, you create the controls and add them to a placeholder.So instead of 20 panels all you need is a placeholder where you add your created controls to.Hope this helps....
|
|
|
|
|
Thank you for idea (better to have something than nothing).
I never did create any control dynamically - It is far easy to create control with some visual tool than to type size, distance between them,.. manually.
From another forum, one developer advice me to use "UserControl".
What do you think of that?
Thank you!
|
|
|
|
|
User controls would essentially be the "best of both worlds". You would create 20 different user controls that represent the different screens you want displayed based on the selected tree node. The benefit here is that you can use the designers and don't have multiple panels stacked on top of each other.
In the right-hand side of the splitter, you would place one panel that will be used to dynamically hold your user controls.
In the AfterSelect event handler of the tree control you will need to do something like this (this is untested code, so it may not be exact):
UserControl userControl;
userControl.Dock = DockStyle.Fill;
userControl.Name = "contentarea";
this.contentPanel.Controls.Add(userControl);
-----------------------------
In just two days, tomorrow will be yesterday.
|
|
|
|
|
You can use Panel, Form, Custom Controls as container for "the right side".
If you can categorize the items on the tree view, you shouldn't have to have 1 panel/form/customcontrol for each treeview node.
There is a .Tag property where you can assign an object to. You can set this property to the object that is tied to the treenode.
I am using Form as a container as an exmaple here. Let's say there are 5 categories of stuff (Class1-Class5)you want to display. when you generate the treeview's node, assign the object to the node:
TreeNode treeSalesOrder = new TreeNode("Class1 Object");
treeSalesOrder.Tag = class1_from_somewhere;
etc etc
So now you have a treeview with node that has tag tied to various objects.
Have 5 forms that display these 5 classes (DisplayClass1-DisplayClass5)
On the AfterSelect event
private void treeView1_AfterSelect(object sender, TreeViewEventArgs e)
{
if (e.Node.Tag != null)
{
SetDisplayPanel(e.Node.Tag);
}
else
{
SetDisplayPanel(null);
}
}
private void SetDisplayPanel(object obj)
{
this.panelDisplayOnRightSide.Controls.Clear();
if (obj != null)
{
Form form = null;
if (obj is Class1)
{
form = new DisplayClass1((Class1)obj);
}
else if (obj is Class2)
{
form = new DisplayClass2((Class2)obj);
}
else if (obj is Class3)
{
form = new DisplayClass3((Class3)obj);
}
else if (obj is Class4)
{
form = new DisplayClass4((Class4)obj);
}
else if (obj is Class5)
{
form = new DisplayClass5((Class5)obj);
}
else
{
return;
}
form.ControlBox = false;
form.FormBorderStyle = FormBorderStyle.None;
form.Dock = DockStyle.Fill;
form.MaximizeBox = false;
form.MinimizeBox = false;
form.TopLevel = false;
//form.Object = obj;
panelDisplayOnRightSide.Controls.Add(form);
form.Show();
form.BringToFront();
}
}
Now I only ripped this code from a prototype program. You can add functions that reuse the 5 forms instead of new a new form every time.
|
|
|
|
|
First of all, I just started learning C# and I'm using VS 2005 Express Ed.
I have a small form with a TreeView control in it. I want to pass a root folder to the following function and populate a TreeView control with directories. My problem is that I don't know how to access the parent nodes or child nodes to add the subdirectory under it's parent directory. The following code simply displays all the folders under the first node.
private void FindAllFolders(string sFolder)
{
try
{
foreach (string dir in Directory.GetDirectories(sFolder))
{
string temp = dir.ToString().Substring(rootFolder.Length);
treeView1.Nodes[0].Nodes.Add(new TreeNode(temp, 1, 2));
FindAllFolders(dir);
}
}
catch (Exception e)
{
MessageBox.Show(e.Message.ToString(), "Directory Search Exception Error",
MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
Thanks,
Mark
|
|
|
|
|
TreeView.Nodes = Gets the collection of tree nodes that are assigned to the tree view control.
TreeView.Nodes[0] = First node in collection.
TreeView.Nodes[0].Nodes = Collection of nodes under first node, i.e the children of the first node.
only two letters away from being an asset
|
|
|
|
|
Ok I understand the collections but if I add an item to the treeview, how do I get a reference to the last node that I inserted?
In VC++/MFC you can get an HTREEITEM returned when you insert an item in a CTreeView.
So when I insert a folder in the TreeView control using C#, and that folder has subfolders I need to then reference that node to insert the subfolder(s) under it.
Mark
|
|
|
|
|
http://msdn2.microsoft.com/en-gb/library/esz34cwb.aspx[^]
Taken directly from the above MSDN link.
TreeNodeCollection.Add Method (String)
Adds a new tree node with the specified label text to the end of the current tree node collection.
public virtual TreeNode Add (
string text
)
Parameters
text
The label text displayed by the TreeNode.
Return Value
A TreeNode that represents the tree node being added to the collection.
only two letters away from being an asset
|
|
|
|
|
I posted a message few weeks ago about me trying to run my exe file on my roomate's laptop, I finally got it to work by taking the crystalreport off the project, so do you guys know if I need to download anything beside the frame work to make my crystal report work on my roomates laptop ???
aPerfectTool
|
|
|
|
|
What is quick method and what is bubble method?
|
|
|
|
|
What are you talking about?
Perhaps sorting... But, please, let us know!
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
|
|
|
|
|
yes sorting but how sort bubble method and how sort quick method?
|
|
|
|
|
Google is your friend...even for homework questions. The answer is probably also in your textbook.
|
|
|
|
|
Rob Graham wrote: Google is your friend...even for homework questions
It won't flame you or get mad
Some people have a memory and an attention span, you should try them out one day. - Jeremy Falcon
|
|
|
|
|
Hence Google is your good friend, see here [^] and here [^].
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
|
|
|
|
|
Hullo Folks,
Am trying to develop a point of sale system for a mobile company.
The point of sale is of distribution of airtime to customers.
The Server is on a Linux box and has MySQL database(This is where the phone Airtime recharge numbers are stored)
Am to develop a client application using C#, the POS is to work in such away that.
The distributor goes to the mobile company, pays say $3000,
So whenever he sells airtime on his account is reduced.
The client will communicate with the server(has MySQL database) over a GSM modem.
However whenever the Distributor requests for Air-time from the server,
The amount he gets will be cached; the amount cached is what he will sell until,
It goes to zero, then he will request more from the server…then cache it….
This will go on and on until his account at the server goes to Zero.
Look at it in this way, you have a bank account, you need say $500,get to the ATM, withdraw the $500,u will have the $500,but your account balance has been reduced by $500,
So you use that $500,till its over and when you need more, you go back to the ATM for more.
How the airtime will be distributed is in 2 ways.
· The point of sale printer will print the recharge number on a piece of paper
Say 123-674-627-63,which will be given to the customer.
· The distributor should be able to directly load the airtime onto the customer’s phone
Can I please have help on how I can go about this one?
Especially the communication over the GSM modem to the server, which is Linux box.
Waskira
|
|
|
|
|
Hi,
I get the above exception while using my code and I really do not know why. The code creates a jagged string array which includes two arrays. Each array holds 20 string items. (In the following code I removed some of it as to not overload this page...).
I then use a for statement (it made en exception using foreach as well), inwhich I create a new Regex variable and use it to replace text. The code is:
string[][] newInfo = new string[2][];
newInfo[0] = new string[20] {"string 1", "string 2", "string 3", ... };
newInfo[1] = new string[20] {"string 1", "string 2", "string 3", ... };
for (int i = 0; i < newInfo[0].Length; i++) {
string parameter = newInfo[0][i];
string value = newInfo[1][Array.IndexOf(newInfo[0], parameter)];
if (value != "-")
{
Regex rxParameter = new Regex("\x7C" + parameter + "=" + ".*" + "\x7C");
p.text = rxParameter.Replace(p.text, "\x7C" + parameter + "=" + value + "\x7C");
}
}
After compiling and running this, the program get stuck at i=3, at the replace function. I dont know why the program is out of memory. Does anyone know what I should do?
Thanks,
Yoni
|
|
|
|
|
Did you look at the call stack for the exception? Did it have any InnerException set? Is the OutOfMemoryException reproducible always at i = 3?
|
|
|
|
|
I am new to C#. I use a text writer called EditPlus to edit the code; and MSDOS to compile it and make an exe out of it. All I get is the exception. I do not know what the "call stack for the exception" or else enything else. I do know that the OutOfMemoryException apears every time I run the program, and every time at i=3. I can also add that i=0 and i=1 goes through quick, less than half a second; i=2 has a small delay, of like half a second, and then i=3 just stalls. I have the free Visual C++ 2005 Express but I have no idea how to use it (i.e. how to load my .cs file).
I know this sound hopeless, but I really do not see a way out of this...
Thanks,
Yoni
|
|
|
|
|
Express edition is really easy to use. You may have to create a new "empty project", then copy and past in your c# program. That should give you all the debugging info so you can see the stack
there are several vedio files for getting started with the express edition. Check microsoft web page.
|
|
|
|
|
Thanks for the tip, I'll check out Microsoft's site..
Yoni
|
|
|
|
|
Is your application a console app or a windows app? If it's a console app, after the OutOfMemoryException occurs, you should be able to see the stack trace on the console window. The stack trace simply lists the sequence of function calls that triggered the exception. Even otherwise, you can wrap the code that you think is causing this exception with a try catch block like this
try
{
}
catch(Exception e)
{
Console.WriteLine(e);
}
VC# Express is a pretty good IDE, you must learn how to use it. You get a very good debugger, at the very least.
|
|
|
|
|
Thanks, I am aware of the try-catch statement, tho it didnt help me so much. Anyway, the problem with the regex has been fixed. The VC# Express is actually a VC++ Express, but I guess C# will work there as well.
Thanks for your help,
Yoni
|
|
|
|
|
How is declared p?
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
|
|
|
|
|
I am using the DotNetWikiBot framework[^].
p is of type Page. I dont think this is the problem, since p.text is of type String.
Yoni
|
|
|
|