|
Hi,
I'm trying to learn C# and am making a little program that retreives product groups from a database.
The productgroups are linked with eachother and can have a unlimited amount of levels.
To give you a id, this is basicly the structure of the table with groups:
id | parent_id
--------------
1 |
2 |
3 | 1
4 | 1
5 | 4
6 | 6
Wat I want to make is a treeview with the nodes arranged this way:
1
|_3
|_4
| |_5
| |_6
2
The code i'm having now is this:
public void PopulateTreeView()
{
DataTable myParentDataTable = getParents();
for (int i = 0; i < myParentDataTable.Rows.Count; i++)
{
TreeNode parentNode = new TreeNode(myParentDataTable.Rows[i]["naam"].ToString());
parentNode.Name = myParentDataTable.Rows[i]["id"].ToString();
treeViewLeft.Nodes.Add(parentNode);
PopulateChilds(parentNode, (int)myParentDataTable.Rows[i]["id"]);
}
}
private void PopulateChilds(TreeNode tnParentNode, int iParentId)
{
DataTable myChildDataTable = getChilds(iParentId);
for (int j = 0; j < myChildDataTable.Rows.Count; j++)
{
TreeNode childNode = new TreeNode(myChildDataTable.Rows[j]["naam"].ToString());
childNode.Name = myChildDataTable.Rows[j]["id"].ToString();
tnParentNode.Nodes.Add(childNode);
}
}
In the last function i've commented-out a line that calls the same function again.
But that's not working the way I want it and i don't know what i should do to get it working right.
Right now it's making the parent nodes and placing all the other nodes inside the parent nodes instead of making parent nodes within the parent nodes and so on.
So, does someone know how to get this wotking?
I probably have to make some changes to the PopulateChilds() function but i've no clue what to do.
I've tried several pieces of code found on this website but i just couldn't get it working the right way.
Thanks!
|
|
|
|
|
public TreeNode PopulateTreeView(DataTable table)
{
TreeNode[] allNodes = new TreeNode[table.Rows.Count];
for(int i=0; i<table.Rows.Count; i++)
{
TreeNode node = new TreeNode(table.Rows[i]["naam"].ToString());
int id = Convert.ToInt32(table.Rows[i]["id"]);
allNodes[id] = node;
}
TreeNode root = new TreeNode();
for(int i=0; i<table.Rows.Count; i++)
{
object o_pId = table.Rows[i]["parent_id"];
TreeNode parent;
if(o_pId is DBNull)
parent = root;
else
parent = allNodes[Convert.ToInt32(o_pId)];
parent.ChildNodes.Add(allNodes[i]);
}
return root;
}
|
|
|
|
|
Thanks for the code.
Though on compiling i'm getting this error:
'System.Windows.Forms.TreeNode' does not contain a definition for 'ChildNodes'
And I think I forgot to mention, but I'm using 2 querys at this moment, one to get the parent groups, and one to get the child groups from one parant.
That should become one query that just retreives the full content of the table with groups?
|
|
|
|
|
|
I know c++ and c# well.But never develop a big project that have so many components and will be extended for long time.
I want to make a program that can be develop by different users.Some of them prefare native app(com dlls, c++ dlls , etc) for components, some of them prefare managed components(.NET base components).
1-)Especially i think that i want to design my UI in c# and then other parts that my algorithms are working with c++ or c# codes.My UI or my application will able to interact between both .net dll or com dlls( i mean native).Is this right way?
I want to learn all your opinions and advices about such a program.I don't want to make mistake.
2-)I mean is this possible?C# host and native dlls.How can i do this?I mean i want to see my roadmap.In which points must i be careful?
3-)Also if i design my programs UI or shell with .net code(like c#) , in future i can utilize .net plugins but if my shell code or UI in c++ i can not write any plugin with managed code.Is this right?
Also if there are any sample applications like that can you send me their links.I really see how must i design my c# exe so it can be interact with both .net and com plugins that develop by differnet users.
Thanks.
I am looking for your answers.
|
|
|
|
|
|
Thanks ravi
I am reading it now.But it seems exe written in C# also plugins written in C#.But my question is especially for C# exe and native plugins (like COM or something else).I want to learn about how i can interact with native components(plugins) from C# exe(UI).
Thanks again.
Good works.
|
|
|
|
|
sawerr wrote: I want to learn about how i can interact with native components(plugins) from C# exe(UI).
Ah. You should be able to define a C# interface that P/Invokes itself into a DLL that exposes a vanilla C API. Using a C API (vs. C++) might be a safer route to work around name mangling issues.
/ravi
My new year's resolution: 2048 x 1536
Home | Music | Articles | Freeware | Trips
ravib(at)ravib(dot)com
|
|
|
|
|
OK.
As i said i want to interact my exe both .net plugins and native plugins.So i must define my interface in two parts.One of them as you said(for native plugins).The other as the link that sent me in your first post(for .net pugin).Is this right?If something wrong please correct it.
Or are there different ways to do this?Any advice?If you know any sample codes it will be perfect for me.Because I can not find such a sample application.
Thanks.
|
|
|
|
|
sawerr wrote: define my interface in two parts
It seems that would be an appropriate way to go. I would first work on defining the .NET one and getting that to work, then extend that to work with a C DLL.
/ravi
My new year's resolution: 2048 x 1536
Home | Music | Articles | Freeware | Trips
ravib(at)ravib(dot)com
|
|
|
|
|
Thanks ravi for all answer.
One more question i have.Why did yo say C DLL?I think i must force developers (that prefer to write native dll) for writing their dlls in COM.Is this wrong?Now i make a decision that:
My UI will be in C# ; plugins which will be in native format must be COM dll.Choosing com technology is wrong?
Thanks again.
|
|
|
|
|
Sorry, yes you could certainly expose a COM interface and P/Invoke that.
/ravi
My new year's resolution: 2048 x 1536
Home | Music | Articles | Freeware | Trips
ravib(at)ravib(dot)com
|
|
|
|
|
I may be an Idiot for asking this but it is friday and my brain is fried, lol. But in a C# Class can you just declare an Enum? Other Classes will use this single Enum as a standard across the application.
|
|
|
|
|
Yes, you can. For example:
public class IceCream
{
protected IceCream()
{
}
public enum Flavor
{
Vanilla = 0,
Chocolate,
Strawberry,
}
} Client classes can then refer to objects of type IceCream.Flavor that could have a possible value of IceCream.Flavor.Vanilla .
/ravi
My new year's resolution: 2048 x 1536
Home | Music | Articles | Freeware | Trips
ravib(at)ravib(dot)com
|
|
|
|
|
Hello,
I have got an problem with Painting in C#. When i resize an image, the right side will get more and more transparency.. i dont want that, but i dont know how to fix it.
A part of the code:
<br />
protected override void OnPaint(PaintEventArgs e)<br />
{<br />
base.OnPaint(e);<br />
<br />
Graphics g = e.Graphics;<br />
<br />
g.DrawImage(Properties.Resources.WindowTopMiddle, 12, 0, this.Width - 22, 40);<br />
g.DrawImage(Properties.Resources.WindowTopLeft, 0, 0, 12, 40);<br />
g.DrawImage(Properties.Resources.WindowTopRight, this.Width - 12, 0, 12, 40);<br />
<br />
g.DrawImage(Properties.Resources.WindowLeft, 0, 40, 8, this.Height - 52);<br />
g.DrawImage(Properties.Resources.WindowRight, this.Width - 8, 40, 8, this.Height - 52);<br />
<br />
g.DrawImage(Properties.Resources.WindowBottomLeft, 0, this.Height - 12, 12, 12);<br />
g.DrawImage(Properties.Resources.WindowBottomRight, this.Width - 12, this.Height - 12, 12, 12);<br />
g.DrawImage(Properties.Resources.WindowBottomMiddle, 12, this.Height - 8, this.Width - 22, 8);<br />
}<br />
You can see, some images have their normal size, and wont get the transparancy..
But the sides, top/bottom middle will.
I dont have changed any default settings, the editor I use is 'Microsoft Visual C# 2005 Express Edition'
Could you please help me?
I look forward to your reply.
- Thomas
-- modified at 15:25 Friday 30th June, 2006
|
|
|
|
|
Hi guys!
I have a click event in one of my forms which is supposed to open another form. How can I ask it to close the current form and open the new form. Basically before I open the new form, close the old form.
Thanks for your help in advance!
sasa
|
|
|
|
|
Try this:
Form1.cs
--------------------------
Form2 form2 = new Form2();
form2.Show();
form1.Close();
|
|
|
|
|
I
SASA_1 wrote: before I open the new form, close the old form.
n the click event handler, you could write something like this:
this.Close();
formw.Visible=true;
I guess it should work.
Regards,
Wasif Ehsan.
|
|
|
|
|
Thank you guys for your help. Neither of these worked. If i use form2.show(); and then form1 or this.close(); it closes both the forms. If I use this.close and then form2.showdialog() offcourse it closes form1 and never opens form 2. If I use form2.showdialog and then this.close then it opens form2 but form1 stays open until I close form2.
What I am trying to do is close form1 as soon as form2 opens. Please help!!!
sasa
|
|
|
|
|
If Form1 is the main form of your application then on closing it terminates the main thread. So Form2 are closed too. You should hide Form1 and close it only after Form2 is closed. Try this in your Form1:
<br />
private void ShowForm2()<br />
{<br />
Form2 form2 = new Form2();<br />
form2.Closed += new EventHandler(form2_Closed);<br />
form2.Show();<br />
Hide();<br />
}<br />
<br />
private void form2_Closed(object sender, System.EventArgs e)<br />
{<br />
Close();<br />
}<br />
|
|
|
|
|
Thank you Alygin, I will try this, I really appreciate your help.
sasa
|
|
|
|
|
Hi,
I want to have a little suggetion from you. I am working in a company which needs to connect to several other companies. Now we need to send data to & from other companies using public domain network like Internet. I want to know what is the best, most efficient & particularly secure way of doing it. Web Services, Sockets or any thing else. The amount of data is average i.e. not very small and not very big.
Regards,
Wasif Ehsan.
|
|
|
|
|
I don't know what kind of budget you have for this project, but this[^] would be a good solution for your needs.
I think the cost, excluding hardware, would be around 20K, including licenses for SQL Server 2005 and BizTalk 2006.
I work with this product since 3 years and I must admit I like it.
--------
"I say no to drugs, but they don't listen."
- Marilyn Manson
|
|
|
|
|
Imho, web services would be the way to go.
If you're unable to keep a server running at either end and don't require the transfer to be in "real time", you could (programmatically) email each other the data.
/ravi
My new year's resolution: 2048 x 1536
Home | Music | Articles | Freeware | Trips
ravib(at)ravib(dot)com
|
|
|
|
|
I mean to say i want to implement that thing in my own application. I dont(can't) use any already built products like BizTalk etc. I am in process of making an application for which i needed suggestion.
Regards,
Wasif Ehsan.
|
|
|
|