|
Is there no standard tree structure supplied with .Net? If not, any recommendations on a third party one?
|
|
|
|
|
Do you mean TreeView, or a hierarchical structure of items? If the hierarchical structure then I have one knocking around somewhere you can have. Let me hunt it out and you can have a copy - I'll probably post it on my blog.
|
|
|
|
|
The "hierarchical structure of items" one
|
|
|
|
|
Is a red-black tree OK with you?
|
|
|
|
|
|
|
|
hi
In my form there is tree view name Account_Tree at the time of adding nodes to the tree view i have done this
Account_Tree.Nodes[0].Nodes.Add("1","Acc");
Now i want to get the Key value
How to do this ?
Dont Get Paid for the Hours you worked, Get Paid for the Work You Have Done in an Hour.
|
|
|
|
|
I don't have VS running at the moment....but here are the steps to answer your own question.
Maybe you want to walk through all added nodes so you start building some kind of structure.
foreach ( TreeNode node in Account_Tree.Nodes[0].Nodes )
{
}
Now inside that loop you are going to rip out the value of one of the fields so
inside the foreach loop you would type node.
Now browse the Intellisense and read the various descriptions to find which property returns the data you want.
|
|
|
|
|
thank u ! unfortunately i found nothing in the intelli sense thats why posted the question here
e.node.name gives the key value but it's used under some events i want to get the value where ever i want in the form
please do help me
Dont Get Paid for the Hours you worked, Get Paid for the Work You Have Done in an Hour.
|
|
|
|
|
I want a method to return different types/classes depending on an in-parameter. More specifically, this is what I want to do:
public struct MyStruct
{
public string myString;
public byte myByte;
public int myInt;
public MyStruct(
string myString_,
byte myByte_,
int myInt_)
{
myString = myString_;
myByte = myByte_;
myInt = myInt_;
}
}
public enum MyStructMemberSelector
{
MY_STRING = 0,
MY_BYTE,
MY_INT
};
public MyStruct[] myStructArray = new MyStruct[]
{
new MyStruct("String 1", (byte)1, 1),
new MyStruct("String 2", (byte)2, 2)
};
public ? getAllItems(MyStructMemberSelector myStructMemberSelector)
{
return ?;
}
.
.
.
string[] myStringArray = getAllItems(MyStructMemberSelector.MY_STRING);
byte[] myByteArray = getAllItems(MyStructMemberSelector.MY_BYTE);
int[] myIntArray = getAllItems(MyStructMemberSelector.MY_INT);
.
.
.
How should I implement the getAllItems method? I am a beginner C#-programmer so please feel free to be specific and include snippets of code in your reply. Thanks in advance for any help!
|
|
|
|
|
the IF will fit here . google strategy pattern also enlightening . refactor condision with strategy also .
f(yf) = yf
|
|
|
|
|
Well, C# only supports function overloading by parameters not return type (which incidentally is not the case for .NET overall) so you either need to create a different named function for each type which is probably useless for what you're trying to do or make your function return an object .
Everything is an object you see, then you can downcast it to whatever you want later. The as keyword is good for this (with reference types).
Regards,
Rob Philpott.
|
|
|
|
|
Thanks for your suggestions. I have a feeling it can be solved somehow using Generics, but I'm not sure how. Anybody have an idea?
|
|
|
|
|
Well I'm not sure if this'll help, but you can do something like this:
public T GetInstanceOf<T>() where T : new()
{
return new T();
}
Standards are great! Everybody should have one!
|
|
|
|
|
arnold_w wrote: How should I implement the getAllItems method?
You shouldn't. What you propose in a real context would likely be considered bad practice from a design perspective. However the code you posted makes no sense. What is the purpose of a class with members myString, myInt, myByte? these are meaningless. Classes are for designing an Object Oriented structure not a Type Oriented structure. Class names and member names should be meaningful not meaningless.
led mike
|
|
|
|
|
Oh lord - you're reconstructing the Variant structure. Please don't do it - there's a reason that we let it die. Don't bring it out of the grave.
|
|
|
|
|
Pete O'Hanlon wrote: Oh lord - you're reconstructing the Variant structure. Please don't do it - there's a reason that we let it die. Don't bring it out of the grave.
Oh Peter, you should know - just like it's progenitor (VB) - it never really died. It's there when you go to bed at night.
You can glance it's fat bulbous a$$ out of the corner of your eye, yet when you look straight at it there's no telling what it'll be. A sock, a chair? Who knows.
But just remember: while you sleep it will come and steal your memory ...
I'm largely language agnostic
After a while they all bug me
|
|
|
|
|
MidwestLimey wrote: But just remember: while you sleep it will come and steal your memory ...
Noooooooooooooooooooo!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
|
|
|
|
Thank you all for your time and help.
|
|
|
|
|
Hello everyone,
I need to build up using C# HTTP Server (HTTP Listener, which could parse various HTTP fields, like post data and return response) and I also need to get an HTTP client which could package various HTTP fields (like URL, post data, etc.).
Are there any sample codes to recommend? I searched MSDN, failed to find any complete client and server samples. I have searched some other samples, which is built on TCP listener, and manually package/unpackage from TCP other than HTTP package level.
thanks in advance,
George
|
|
|
|
|
Hi All,
Is there a way to suppress/hide a section programmatically???
Thanx.
|
|
|
|
|
I've got some GUI win forms project1 with some class developed say SomeClass. That class has serialization ability to save its object to file and load it later.
SomeClass.Serialize()
{
...
IFormatter formatter = new BinaryFormatter();
formatter.Serialize(stream, this);
...
}
SomeClass SomeClass.Deserialize()
{
using (Stream stream = new FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.Read))
{
IFormatter formatter = new BinaryFormatter();
return (SomeClass)formatter.Deserialize(stream);
}
}
Now the GUI has assemblyinfo.cs with its assembly AssName1 . I run the GUI and serialize the class to file. In that file that AssName is present at the beggining of the file.
Now I have another project2 with different name and assembly name AssName2. I added that SomeClass.cs code to that project and try to deserialize the object from that project.
It says:
can not find assembly "AssName1, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"
If I serialize that class from project2 it puts AssName2 to the serialized file. So it seems you can not share the serialized versions of SomeClass between differently named projects?
How can I deserialize the SomeClass object in project2 which was saved in project1?
chesnokov
|
|
|
|
|
The problem you have is that you've duplicated the code for SomeClass in both assemblies. This will make them different classes. (A classes full name includes it's assembly name).
What you need to do is only define SomeClass in one place, and reference it from everywhere that needs it. I would suggest you create a 3rd project (of type class library), call is SharedLibrary and place SomeClass.cs in that project. Then reference SharedAssembly from both Project1 and Project2.
(You can add references by right clicking on the project in the solution explorer and clicking "add reference", then using the browse tab to brose to the file.)
You can also create 2 solutions. The first containing Project1 and the SharedLibrary and the second containing project2 and the SharedLibrary. Now when you click "add reference" the SharedLibrary will appear under the projects tab.
Simon
|
|
|
|
|