• Popular Now

• 12
• 27
• 9
• 9
• 20

Archived

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

General C# programming Questions

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

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 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 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 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 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 followingSystem.Windows.Forms.ListViewItem li = new System.Windows.Forms.ListViewItem("New Item");//this next line throws the invalid cast exceptionli.Tag = new TagEx(1L);

Share on other sites
You can try CodeProject for C# forums. The web site also has tons of code for MFC and general Windows programming.

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!"