Archived

This topic is now archived and is closed to further replies.

General C# programming Questions

This topic is 5587 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I have a few questions if there are any C# experts out there. 1. Has anyone found a really good forum for c# help? This is my first time posting here so it might be good, but then again this is gamedev.net not appdev.net... Now for the real questions: 2. I have a TreeView on a form that has a context menu assigned to it. When I right click to bring up the menu, it pops up and selects the node I right-clicked on. Then when I press one of the menu items, or cancel the menu by clicking outside of it, the node selected returns to the previously selected node. The problem is, I cant figure out how to identify the node selected when the context menu is up in the code. Anybody know how? 3. I have successfully inherited a TreeNode into the class I made called TreeNodeEx, which has some extra variables that I need. I can add/edit/delete this new node class to any existing treeview using casting and all seems well. I tried to do the same thing with a ListViewItem by inheriting it to a ListViewItemEx class and adding a few variables. Suprisingly, I cannot add this ListViewItemEx to a ListView class, no matter what I do. Question is, why can''t I do this? Any help to these questions would be greatly appreciated. Thank You.

Share this post


Link to post
Share on other sites
quote:
Original post by ISOPimp
I have a few questions if there are any C# experts out there.

1. Has anyone found a really good forum for c# help? This is my first time posting here so it might be good, but then again this is gamedev.net not appdev.net...


I prefer the official newsgroup: news://msnews.microsoft.com/microsoft.public.dotnet.languages.csharp . However there are also more specialized newsgroups for technologies like Windows forms, GDI+ and ASP.NET.

quote:

2. I have a TreeView on a form that has a context menu assigned to it. When I right click to bring up the menu, it pops up and selects the node I right-clicked on. Then when I press one of the menu items, or cancel the menu by clicking outside of it, the node selected returns to the previously selected node. The problem is, I cant figure out how to identify the node selected when the context menu is up in the code. Anybody know how?


Wouldn''t the public TreeNode GetNodeAt(int, int); method be useful here?
quote:

3. I have successfully inherited a TreeNode into the class I made called TreeNodeEx, which has some extra variables that I need. I can add/edit/delete this new node class to any existing treeview using casting and all seems well. I tried to do the same thing with a ListViewItem by inheriting it to a ListViewItemEx class and adding a few variables. Suprisingly, I cannot add this ListViewItemEx to a ListView class, no matter what I do. Question is, why can''t I do this?


What happens when you try?


"When you know the LORD you have no need for masturbation!"

Share this post


Link to post
Share on other sites
Yep, use the GetNodeAt() method. If you need further accountability for each node...there is an Index property on TreeNodes. Also, there is a Tag property on nodes, that you could set to a GUID for each of the nodes.

"Wisdom is proportionate to your reference base. Intelligence is the ability to appropriately use that Wisdom."


[edited by - Leathrewulfe on August 29, 2002 10:14:15 PM]

Share this post


Link to post
Share on other sites
Inheritance may not be required for "adding a few variables" to a tree or list. You should look into the Tag object. It has a infinate number of cool uses :-)

-SniperBoB-

-SniperBoB-


What if The Matrix was recursive?

Share this post


Link to post
Share on other sites
quote:
Wouldn''t the public TreeNode GetNodeAt(int, int); method be useful here?


I believe it is useful, I didnt even see it. I tried to implement this but I then realised that the PopUp event handler doesnt pass the mouse position, and I cant find information about getting the mouse position independently. Any help with this?

quote:
What happens when you try?

quote:
You should look into the Tag object. It has a infinate number of cool uses :-)


Both of these options throw an invalid cast exception.

Here are some code snippets of how I used the tag object.

  //Here is my own derived tag class

//--stripped of 2 other long properties for simplicity--

public class TagEx: object
{
private long m_UniqueID;
public TagEx(): base()
{
m_UniqueID = 0L;
}
public TagEx(long UniqueID): this()
{
m_UniqueID = UniqueID;
}
public long UniqueID
{
get
{
return m_UniqueID;
}
set
{
m_UniqueID = value;
}
}
}


//In another section of code I do the following

System.Windows.Forms.ListViewItem li = new System.Windows.Forms.ListViewItem("New Item");
//this next line throws the invalid cast exception

li.Tag = new TagEx(1L);

Share this post


Link to post
Share on other sites
quote:
Original post by ISOPimp
I cant find information about getting the mouse position independently. Any help with this?


System.Windows.Forms.Cursor.Point returns the cursor position in screen coordinates.

quote:

public class TagEx: object


Deriving explicitly from object is redundant, but harmless.
quote:

li.Tag = new TagEx(1L);


There is no reason whatsoever that line would throw InvalidCastException, so I would venture to guess that throw comes from within the ctor proper. Maybe the problem is with the two properties you omitted?


"When you know the LORD you have no need for masturbation!"

Share this post


Link to post
Share on other sites
Thank you very much Arild and others. The problem with the casting was one of those "I can''t believe I didn''t see that" type problems. I was doing 2 other casts on the same line to get some DataRow elements into the TagEx but I was casting the wrong column.

All problems are now solved (for now). Thanks again.

Share this post


Link to post
Share on other sites