Click here to Skip to main content
15,888,454 members
Home / Discussions / C#
   

C#

 
GeneralRe: How to change system date in .NET Pin
Heath Stewart4-May-04 8:27
protectorHeath Stewart4-May-04 8:27 
GeneralRe: How to change system date in .NET Pin
Jeff Varszegi4-May-04 8:33
professionalJeff Varszegi4-May-04 8:33 
GeneralRe: How to change system date in .NET Pin
Heath Stewart4-May-04 8:46
protectorHeath Stewart4-May-04 8:46 
GeneralRe: How to change system date in .NET Pin
eggie54-May-04 15:50
eggie54-May-04 15:50 
GeneralUpdate dataset Pin
Appelz4-May-04 2:39
Appelz4-May-04 2:39 
GeneralRe: Update dataset Pin
Heath Stewart4-May-04 4:31
protectorHeath Stewart4-May-04 4:31 
Generalassociate the ContextMenu Pin
cristina_tudor4-May-04 2:23
cristina_tudor4-May-04 2:23 
GeneralRe: associate the ContextMenu Pin
Bill Dean4-May-04 4:28
Bill Dean4-May-04 4:28 
Cristina,

I am doing something like this right now actually.

Since the TreeNodes don't have a ContextMenu associtated with them, the thing to do is change the ContextMenu associate with the parent TreeView based on where the cursor is. Do this by handling the MouseMove event on the TreeView control. I derive a new class of TreeNode for each "kind" of node I use. This lets you use the node type to decide which menu to show.

Something like:

private void treeView1_MouseMove(object sender, System.Windows.Forms.MouseEventArgs e)
{
	TreeNode tn=treeView1.GetNodeAt(treeView1.PointToClient(System.Windows.Forms.Cursor.Position));
	if (tn!=null)
	{
		switch (tn.GetType ().ToString ())
		{
			case "DerivedTreeNodeClass1":
				this.ContextMenu = ContextMenu1;
				break;
			case "DerivedTreeNodeClass2":
				this.ContextMenu = ContextMenu2;
				break;
			default:
				this.ContextMenu = DefaultContextMene;
				break;
		}
	}
	else
	{
		this.ContextMenu = null;
	}
}


You can use the same idea and handle it on popup too...at least I can't think of a reason why that wouldn't work. You also don't need to derive new TreeNode classes. You just need some way to tell, from the node itself, what menu you need to show.

Hope this helps,
Bill
GeneralRe: associate the ContextMenu Pin
Mike Dimmick4-May-04 5:29
Mike Dimmick4-May-04 5:29 
GeneralRe: associate the ContextMenu Pin
Bill Dean4-May-04 5:47
Bill Dean4-May-04 5:47 
GeneralRe: associate the ContextMenu Pin
Syed Abdul Khader4-May-04 5:44
Syed Abdul Khader4-May-04 5:44 
Generaldrop down list in c# Pin
mrv114-May-04 2:01
mrv114-May-04 2:01 
GeneralRe: drop down list in c# Pin
Bill Dean4-May-04 4:31
Bill Dean4-May-04 4:31 
GeneralRe: drop down list in c# Pin
Heath Stewart4-May-04 4:43
protectorHeath Stewart4-May-04 4:43 
GeneralID3 decision tree algorithm in C# Pin
Member 7511394-May-04 1:15
Member 7511394-May-04 1:15 
GeneralRe: ID3 decision tree algorithm in C# Pin
leppie4-May-04 7:13
leppie4-May-04 7:13 
GeneralException Reporting Pin
sreejith ss nair4-May-04 1:13
sreejith ss nair4-May-04 1:13 
GeneralRe: Exception Reporting Pin
Colin Angus Mackay4-May-04 1:28
Colin Angus Mackay4-May-04 1:28 
QuestionHow to customize PropertyGrid ToolTip Pin
LotusM4-May-04 0:53
LotusM4-May-04 0:53 
Generalcombobox datasource Pin
brain2cpu4-May-04 0:21
professionalbrain2cpu4-May-04 0:21 
GeneralRe: combobox datasource Pin
Colin Angus Mackay4-May-04 0:42
Colin Angus Mackay4-May-04 0:42 
GeneralUpdating More than One table Pin
sreejith ss nair3-May-04 23:46
sreejith ss nair3-May-04 23:46 
GeneralRe: Updating More than One table Pin
Heath Stewart4-May-04 4:13
protectorHeath Stewart4-May-04 4:13 
GeneralAlan Murta's - General Polygon Clipper Pin
d-mon3-May-04 22:55
d-mon3-May-04 22:55 
GeneralRe: Alan Murta's - General Polygon Clipper Pin
Daniel Turini4-May-04 0:07
Daniel Turini4-May-04 0:07 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.