|
First I must state I'm newish to C#. I am/was a decent Perl script kiddy.
I can not seem to locate good tutorials or code examples that help me to build a simple treeview. Some of the ones I have seen are pretty complex that I can't quite grasp it, the other easy ones are so abstract it teaches me nothing about implementation.
I will show what code I have then ask my question below it:
TreeNode parentNode = new TreeNode();
parentNode.Text = "Name";
parentNode.Tag = 1;
parentNode.ExpandAll();
treeView1.Nodes.Add(parentNode);
TreeNode childNode = new TreeNode();
childNode.Text = "Child";
childNode.Tag = 2;
parentNode.Nodes.Add(childNode);
This creates a very simplistic Parent called "Name" and a Child called "Child".
Questions:
1) This works for creating a single child, but can someone explain to me how I reference the parent specifically to add more children? To rephrase: If I have many Parents, how do I pick one of the parents to add more children?
2) What exactly is the .Tag used for?
3) How do I make a variable or object that would store one specific parent or child so that I could read/write data, or add add children too it?
4) Why is it so hard to find a tutorial or books that contain information about TreeView?
Hope this is appropriate for my first post here.
Thanks,
TriX
|
|
|
|
|
1a. You can keep a reference to the node(s) that you want to add to or
1b. Use the overload Nodes.Add(string key, string text) when adding a node. You can then use the Nodes.Find method to search your nodes based on the key. This returns a Treenode array as each key doesn't have to be unique - I'd recommend making sure each key is unique though then there will only ever be one element in the array.
2. The tag can be used for anything you like.
A common way is:
Imagine a tree of Employee names - the tag could contain an employee object with all their data but the node's text would probably only show their name (by using the ToString method on the employee object maybe?). This way, if you wanted to show all the employee's data, you'd have it handy without having to look it up again based on their name.
This can obviously become memory intensive so in the case where a lot of nodes are expected it might be better to use the tag to store the employee ID only, then when you need their data you can look up based on a field that is unique to them.
BTW, you don't have to use the tag prperty on any node if you don't wish to.
3. Just use a TreeNode object (see 1a)
4. There's plenty around that won't seem so convoluted once you've got the hang of them.
DaveBTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)Expect everything to be hard and then enjoy the things that come easy. (code-frog)
|
|
|
|
|
Hi.
How can we override OnFormClosing method ?
Science doesn't limit
Science is for everyone
|
|
|
|
|
in inherited form just add this code
protected override void OnFormClosing(FormClosingEventArgs e)
{
base.OnFormClosing(e);
}
in msdn said :
Notes to Inheritors When overriding OnFormClosing in a derived class, be sure to call the base class's OnFormClosing method so that registered delegates receive the event
hope it helps
dhaim
programming is a hobby that make some money as side effect
|
|
|
|
|
Thank you my friend
|
|
|
|
|
hi every body
i want know how can i search in text files (*.doc,*.txt)
by c#
I want give the program specefic folder and it will search in all files in it
how can i do this ??
thanks in advance
|
|
|
|
|
i dont know about *.doc files cause the format is different from *.txt
Youll use the DirectoryInfo class to get a list of all the text files within it.
then you can foreach that list and inside the loop create a fileStream that you point to the path of the current item in the loop. You then need to create a StreamReader and point it to your fileStream. you can then declare a string variable and call StreamReader.ReadToEnd(). after that you can use String.Contains("Text your looking for") to see if you text is in fact in your file!
Heres an example in C#
DirectoryInfo dirInf = new DirectoryInfo(@"C:\");
FileInfo[] files = dirInf.GetFiles("*.txt");
foreach (FileInfo currentFile in files)
{
FileStream fs = new FileStream(currentFile.FullName, FileMode.Open);
StreamReader reader = new StreamReader(fs);
string fileContent = reader.ReadToEnd();
if (fileContent.Contains("the text your searching for"))
{
MessageBox.Show("The File " + currentFile.FullName +
" Contains the text your searching for");
}
fs.Flush();
reader.Close();
fs.Close();
}
remember to add using System.IO;
Harvey Saayman - South Africa
Junior Developer
.Net, C#, SQL
you.suck = (you.Passion != Programming & you.Occupation == jobTitles.Programmer)
1000100 1101111 1100101 1110011 100000 1110100 1101000 1101001 1110011 100000 1101101 1100101 1100001 1101110 100000 1101001 1101101 100000 1100001 100000 1100111 1100101 1100101 1101011 111111
|
|
|
|
|
Hi
I am a university student and working on assignment convert swf to exe file. From the last two days I have searched a lot, i found softwares written in C# that can do it but didn't get any programming help how to do this.
Thanks in advance
|
|
|
|
|
Okay, i found this: http://bytescout.com/swfscout_flash_demo_exe_to_swf.html[^]
Which is taking the swf out of the exe, it also comes with source. I'm not sure what language it is since i didn't look but...
Anyway, if you know how to take the SWF out, then that means you know where to put the SWF back in. So you may be able to figure it out from this.
Remember, if you get stuck with a specific problem then feel free to ask away.
My current favourite word is: Nipple!
-SK Genius
Game Programming articles start - here[ ^]-
|
|
|
|
|
Dear Sir,
Thanks for your reply i have found the link there to convert swf to exe. http://bytescout.com/swfscout_flash_demo_swf_to_exe.html. But the downloaded file is not working. I have seen some help on this site too, I will try myself and hopefully i will extract some data from the site. If I will I will contact you. Hope you will help me.
Thank You
|
|
|
|
|
Hi everyone,
I'm working on a solution were i have changed the default namespace to something like the following (in a class libary):
XGSDev.XeroxOrderTracking.OrderTrackingService.ComsLayer
Now i've also used some web references too. The problem is that the webreference do not follow this namespace. They are instead at ComsLayer.<what ever="">
I would have expected
XGSDev.XeroxOrderTracking.OrderTrackingService.ComsLayer.<web service="" name="" here=""> to be correct.
Normally this isn't a problem but now because of this i'm having lots of ambiguous variables and methods.
I'm sure i'm missing something simple but i can't think what it is.
Thanks
Phil
|
|
|
|
|
Ok, I figured out that if I change the reference.cs file for each of my web references then everything works. The namespaces match and now I can access what I want. However, as i'm sure you'll all know as soon as I update the webreference it reverts back to the other names space of ComsLayer.<webservicename>.
So what i need to do is be able to set a default value of this namespace to XGSDev.XeroxOrderTracking.OrderTrackingService.ComsLayer.<webservicename>
I found out that in the properties of the Reference.map you can enter a custom tool namespace. Enter your namespace here and everything will work!!
Phil
|
|
|
|
|
hi. How can you change the background image of a picture box when a mouse is hovered on it? I want it to change images as it hovers and leaves. My current image was set to the properties pane of visual studio 2005. How can you code the hover part?
|
|
|
|
|
Hi,
Try the following code snippet:
BEGIN CODE
Public Class Form1
Dim image1 As String = Application.StartupPath + "\Water lilies.jpg"
Dim image2 As String = Application.StartupPath + "\Winter.jpg"
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Me.PictureBox1.BackgroundImage = Image.FromFile(image1)
End Sub
Private Sub PictureBox1_MouseHover(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PictureBox1.MouseHover
Me.PictureBox1.BackgroundImage = Image.FromFile(image2)
End Sub
Private Sub PictureBox1_MouseLeave(ByVal sender As Object, ByVal e As System.EventArgs) Handles PictureBox1.MouseLeave
Me.PictureBox1.BackgroundImage = Image.FromFile(image1)
End Sub
End Class
END CODE
Hope this helps .
Regards,
John Adams
ComponentOne LLC
|
|
|
|
|
WOW THANKS! I just converted it into C# code. Thanks!
|
|
|
|
|
I am interested in writing a program in C# to monitor my bandwidth usage (up and down) on my satellite internet. Is anyone aware of existing source code? Any suggestions?
|
|
|
|
|
There's a few on SourceForge. Check out FreeMeter[^].
(If you choose not to make your own, I recommend NET Traffic Meter[^]. It's very, very simple and works well.)
|
|
|
|
|
Tnx for pointing we in the right direction
|
|
|
|
|
Free meter you suggested is exactly what I needed. Downloaded source and compiled under Net 2005 without problem. I will be able to extract what I need from there. Many Thanks.
Electriac
|
|
|
|
|
Awesome. Please ignore this next sentence if you're aware of it: Free Meter is licensed under the GPL, so if you make any modifications please respect its license.
|
|
|
|
|
Hi,
I need to collect the images from an RTF file as image objects that I can work on individually. Any ideas?
I tried loading the RTF file in the RTFTextBox in WinForms. The images show up correctly, but I still haven't figured out a way of accessing them directly.
Hope someone can help. Thanks!
Sarab
|
|
|
|
|
|
Hi Giorgi,
Yes - that's the problem! I've found plenty of examples describing how to insert images into RTF but none on how to do the opposite! Am surprized no one else has had the need for this..
Hope someone else can help ... ?
Sarab
|
|
|
|
|
The RTF specification is available here[^] if that's any help. I think you're gonna have to parse the rtf and reconstruct the image from the data that's embedded.
DaveBTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)Expect everything to be hard and then enjoy the things that come easy. (code-frog)
|
|
|
|
|