Click here to Skip to main content
15,886,058 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello,

Need to disable one of context Menu Item.i.e.ContextMenu contains 3 items and i have to disable only 2 item. I am using following code but it disable all Items.

MenuItem pictureBoxMenuItem = (MenuItem)PictureBoxContextMenu.Items.GetItemAt(2);
     pictureBoxMenuItem.IsEnabled = false;



Thanks
Posted
Updated 20-Nov-11 23:42pm
v2

 
Share this answer
 
v2
if u want to disable Exit item then on menubar Exit right click and in property
Enabled make False.

if it helps plz reply or accept solution.
 
Share this answer
 
v2
u hv 3 menuitems as Add,Delete,Exit,then in design time right click on Exit .
go to in properties,and
make Enabled property False.
 
Share this answer
 
Comments
Denno.Secqtinstien 21-Nov-11 9:31am    
if this solves your answer then hit star ???
you can disable right click using this code :-

<script type="text/javascript">
document.oncontextmenu=new Function("return false");
</script>

and for Ctrl + U, try this one :-

<b><Javascript file></b>

var isnn,isie
if(navigator.appName=='Microsoft Internet Explorer') //check the browser
{ isie=true }

if(navigator.appName=='Netscape')
{ isnn=true }

function key(k)
{
if(isie) {
if(event.keyCode==17 || event.keyCode==18 || event.keyCode==93) {
return false;
}
}

if(isnn){
return false; }
}

if (document.layers) window.captureEvents(Event.KEYPRESS);
if (document.layers) window.captureEvents(Event.MOUSEDOWN);
if (document.layers) window.captureEvents(Event.MOUSEUP);
document.onkeydown=key;
document.onmousedown=right;
document.onmouseup=right;
window.document.layers=right;


<b><html file></b>

<html>
<head>
<Script language="JavaScript" src="security.js"></script>
</head>
<html>
 
Share this answer
 
Comments
Denno.Secqtinstien 21-Nov-11 9:34am    
if this solves your answer then hit star ???
Philippe Mori 21-Nov-11 19:09pm    
Please format your solution correctly.
Denno.Secqtinstien 22-Nov-11 1:49am    
got wrong question please ignore this one ..
fjdiewornncalwe 5-Dec-11 14:54pm    
This is not a web question.
Not yet Manisha...I am creating Context Menu at run time.and i want to disable one of item from it when particular event occurs.Can u suggest me another way?
 
Share this answer
 
Comments
Manisha Tambade 22-Nov-11 5:18am    
dont post ur doubt in solution,use comment.
can u post code snipet,the way u creating runtime ContextMenu.
KIDYA 22-Nov-11 7:37am    
PictureBoxContextMenu = new ContextMenu();
pictureBoxMenuItem = new MenuItem();
pictureBoxMenuItem.Header = "Add";
pictureBoxMenuItem.IsEnabled = false;
pictureBoxMenuItem.Tag = currChannel;
pictureBoxMenuItem.Click += new RoutedEventHandler(MenuItem1_Click);
PictureBoxContextMenu.Items.Add(pictureBoxMenuItem);

pictureBoxMenuItem = new MenuItem();
pictureBoxMenuItem.Header = "Edit";
pictureBoxMenuItem.IsEnabled = false;
pictureBoxMenuItem.Tag = currChannel;
pictureBoxMenuItem.Click += new RoutedEventHandler(MenuItem2_Click);
PictureBoxContextMenu.Items.Add(pictureBoxMenuItem);

pictureBoxMenuItem = new MenuItem();
pictureBoxMenuItem.Header = "Exit";
pictureBoxMenuItem.IsEnabled = true;
pictureBoxMenuItem.Tag = currChannel;
pictureBoxMenuItem.Click += new RoutedEventHandler(MenuItem3_Click);
PictureBoxContextMenu.Items.Add(pictureBoxMenuItem);

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900