|
If you knew this path at compile time then you may just want to hold onto a reference to the TreeNode object when you created it so it will be handy.
The alternative is to just drill down on the Nodes collection to get to it; again, if you knew where you put it at compile time.
If the revelation of it became known at runtime, i.e. it was passed in on an event, just call the Remove method on the node itself.
Yet another method would to mark special nodes by putting something in the Tag property, you could then enumerate the entire tree and pluck out the nodes your after.
Does this answer the question?
|
|
|
|
|
Thanks for your help. Unfortunately, the tree is constructed and used for another purpose before I want to deal with opening it up to a specific directory. I took your advice, however. After I developed the tree, I ended up just enumerating through it until the path specified by the user was the same as one of the node's full name. I think what I was looking for was a method for the TreeView to automatically return a node given a path. Like:
TreeNode returnNode(string path)
which would ideally return the node whose fullName matched "path" (or null if no match could be found). Which actually happens the function I ended up implementing. Anyway, thanks for the help.
- Sabran
|
|
|
|
|
When you see the PathSeparator property of TreeView and the FullPath property of TreeNode, It would leave you to believe that it also has a built-in searching mechanism that utilizes these. If it does, I have not found it.
Regards
|
|
|
|
|
Hello everyone!,
I've lingered code project reading posts etc for a quite a while (say 3-4 months). Im proud to say I am now part of the community.
Ok now for my first question: Recently i have decided to mess around a little with .net so i have made an app, a MDI app. I have 3 different forms inside it as child windows. How would it be possible to exchange data across the forms(I.E. Click a button on one form have my app retreive a string from a text box on another and add the string into a list box on the third)? I am capable of doing each of thoes if it was on one form but im unware to how I would make the three Forms communicate. I hope you can understand my question, if not let me know i will gladly rephrase it so that it may possibly be understandable.
|
|
|
|
|
brian1415 wrote:
Im proud to say I am now part of the community.
Welcome
I can think of a couple different options, both require the child forms to be aware of the parent. The first one is the best though and I'll explain how to do it.
The first has the child forms knowing only about itself and the parent. When data needs to be exchanged it tells the Parent form to do it.
The second requires the child forms to know about the parent and the other child windows. This can make maintenance a nightmare but opens the door up a bit for what you want to do.
Assume the parent form is of type ParentForm. Then to get a reference to the parent from the child you would do ParentForm p = this.Parent as ParentForm .
Now that you have a reference to the ParentForm you can call methods on it... When you want to pass data around you tell the parent to pass the data by calling a method on it. That method tells the other child window what to do. The ParentForm is aware of all child windows.
Difficult for me to explain in English, but pretty easy to do in code
James
Simplicity Rules!
|
|
|
|
|
Hello thank you for the help!, but I've been fiddling around with my app trying to do what you suggested but im not sure if I understand ... I know you are probably busy but if it would not be to much trouble could you possibly post/Email me a quick code snippet so that I may understand? My knoledge of WinForms is very limited.
Thank you once again...
|
|
|
|
|
Heres the names I will use.
Classes- ParentForm - The MDI Parent
- ChildFormA - One of the child forms
- ChildFormB - Another child form
- ChildFormC - The last child form
- DataA - Data class for ChildFormA
- DataB - Data class for ChildFormB
- DataC - Data class for ChildFormC
Class instances stored in ParentForm class- childA - ChildFormA
- childB - ChildFormB
- childC - ChildFormC
Now a little setup
In ParentForm
public void SendToChildA(DataA data)
{
childA.Data = data;
childA.DataSent();
} Do similar for the other children (B and C)
Now in each of the ChildForm s create a Data property which is of the same type as the class associated with it. Also create a method called DataSent which will actually do the processing of the data for the child form.
Now when you want to send data from one child form to another you call the appropriate method on the parent.
....
ParentForm parent = this.Parent as ParentForm;
DataB data = new DataB();
parent.SendToChildB(data);
.... If you wanted to truly adopt .NET practices you would replace the DataSent method and Data properties on the client with events; but for a quick example this works. I'll leave switching to an event as an exercise for you, its not too difficult
HTH,
James
Simplicity Rules!
|
|
|
|
|
Thank you very much I apreciate you help!
|
|
|
|
|
Anyone know how to find the control I am currently over without cycling through each one?
ie. Control ctrl = this.hittest(x,y);
cant find hit test anywhere.
thanks
|
|
|
|
|
Check something like this:
protected override void OnMouseOver(System.Windows.Form.MouseEventArgs mea)
{
mea.<code>[SomeMethod()]</code>
}
Sorry, not at home(with .NET Framework) to check the exact value, hope this will lead you in the right direction.
Nick Parker
J
This is a non-Calculus course as long as you know things like line integrals and surface integrals...
|
|
|
|
|
|
Thanks, GetChildAtPoint() works perfectly.. except for these two problems:
1) it takes relative x and y to that control's clientarea. so this.GetChildAtPoint(10,10) is very different from txtBlah.GetChildAtPoint(10,10)... which leads to my next problem:
2) get child only gets one child down. I would rather have this.GetChildAtPoint(x,y) get the control inside of the groupbox at x,y and not the groupbox. code to get only the second layer looks like this:
Control m_ctrl = this.GetChildAtPoint(new System.Drawing.Point( e.X, e.Y));<br />
Control m_subCtrl = m_ctrl.GetChildAtPoint(new System.Drawing.Point( e.X - m_ctrl.Left, e.Y - m_ctrl.Top ));<br />
any ideas (without recursion, please )
|
|
|
|
|
Point pt = new Point(x, y);
Control parent = this;
Control child = parent.GetChildAtPoint(pt);
while (null != child)
{
pt = parent.PointToScreen(pt);
pt = child.PointToClient(pt);
parent = child;
child = parent.GetChildAtPoint(pt);
}
BTW, If there is a functional equiv. to the MapWindowPoints API, I am all ears...
|
|
|
|
|
A slight improvement to reduce the number of point mappings...
Point pt = new Point(x, y);
Control parent = this;
Control child = parent.GetChildAtPoint(pt);
if (null != child)
{
pt = parent.PointToScreen(pt);
do
{
parent = child;
child = parent.GetChildAtPoint(parent.PointToClient(pt));
} while (null != child);
}
|
|
|
|
|
if (c_urwondering)<br />
{
I have a form with three tabs in a tabcontrol and many controls inside each tab. even controls inside groupboxes in each tab. many.
this form represents a scrollable row in a recordset. it has a vertical scrollbar on the right.
I attach:
this.MouseWheel += new System.Windows.Forms.MouseEventHandler(this.Dialog_MouseWheel);
i want to only allow scrolling when the mouse is not on data driven controls. so scroll when over a label, but not a combobox; inside a groupbox, but not inside a checkbox in a groupbox. etc
}
|
|
|
|
|
I use this connection string to connect to database:
connString=@"Provider=Microsoft.Jet.OLEDB.4.0;User ID=Admin;Password=mypass;Data Source=..\..\Tennis.mdb;Jet OLEDB:System Database=E:\Program Files\Microsoft Office\Office\System.mdw" ;
but ecxeption thrown:
---------------------------
---------------------------
System.Data.OleDb.OleDbException: Not a valid account name or password.
at System.Data.OleDb.OleDbConnection.ProcessResults(Int32 hr)
at System.Data.OleDb.OleDbConnection.InitializeProvider()
at System.Data.OleDb.OleDbConnection.Open()
at Tennis.MainForm..ctor() in f:\visual studio projects\projectc#\tennis\mainform1.cs:line 65
---------------------------
OK
---------------------------
Any suggestion?!!!
Mazy
"The path you tread is narrow and the drop is shear and very high,
The ravens all are watching from a vantage point near by,
Apprehension creeping like a choo-train uo your spine,
Will the tightrope reach the end;will the final cuplet rhyme?"Cymbaline-Pink Floyd
|
|
|
|
|
1. All of the examples I have seen using "System database=" spell it with a lower-case "database" as in "System database=" not "System Database=". I really don't know if this matters or not.
2. Are you using a general password protected database, or a user-level secure database? If you are using a general password protected database, the connection string magic is ";Database Password=mypass;".
Regards
|
|
|
|
|
Scratch #1, I eliminated it as a potential problem...
|
|
|
|
|
Thanks Neil,
The Magic WAS the ";Database Password=password;" (with a ;Jet OLEDB before it
I feel relifed.
Mazy
"The path you tread is narrow and the drop is shear and very high,
The ravens all are watching from a vantage point near by,
Apprehension creeping like a choo-train uo your spine,
Will the tightrope reach the end;will the final cuplet rhyme?"Cymbaline-Pink Floyd
|
|
|
|
|
Any time...
Somehow I originally had the notion that you were attempting user-level security...
Regards
|
|
|
|
|
I am using Visual Studio 7.0 to begin to learn Socket programming. Unfortunatley the System.Net and System.Net.Sockets namespaces do not exist. When I compile my project I get the following error.
"The type or namespace name 'Net' does not exist in the class or namespace 'System' (are you missing an assembly reference?)"
Now Ive been looking on the net for a solutions to this problem and every one says to add a refrence to the System.Net.dll on my machine. Ive looked and looked but the System.Net.dll does not exist. Is there anywhere I could download it?
Thanks
|
|
|
|
|
Have you made sure you installed the .NET framework.
I had this problem once and I had to uninstall the Framework and reinstall and everything worked fine.
|
|
|
|
|
You're right, it doesn't exist; its part of System.dll which declares quite a few other types. Ensure that it is properly referenced in your project (it is by default but you could have accidentally removed it).
James
Simplicity Rules!
|
|
|
|
|
Just to make sure I added a refrence to every .NET dll to the project including System and there is still no System.Net namespace.
Is there a place where I could download it?
Thanks
|
|
|
|
|
System.dll is where the System.Net namespace is declared (I checked with Anakrino) so that means you have a spelling error, or your .NET install is corrupt
I don't think there is any place that has that single dll online, my System.dll is 1.10MB and was last modified January 5th, 2002; check yours to make sure it is the same. You can find it in %WINDIR%\Microsoft.NET\Framework\%DOTNET_VERSION%\
HTH,
James
Simplicity Rules!
|
|
|
|