Windows Develop Bookmark and Share   
 index > Windows Forms Data Controls and Databinding > ContextMenuStrip RowTemplate
 

ContextMenuStrip RowTemplate

Hello, I have a DataGridView.The RowTemplate.ContextMenuStrip is assigned.
I want to programatically disable menustripitems.
In the handler for the event Opening on the contextMenuStrip i have cms.Items[0].Enabled=false

But the menuitem is still enabled..it is clickable..Any idea why is this happening ?
emarinescu  Tuesday, March 03, 2009 12:03 PM
Thanks for your reply..I allready resolved it by handling the RowContextMenuStripNeeded for the DataGridView..I assign there the ContextMenuStrip property of args parameter..here is the enabled/disabled logic..
Thanks anyway for responding
emarinescu  Thursday, March 05, 2009 12:46 PM
Hi,

I'm just throwing my 2 cents in, hoping it will be helpfull.

I had a similar requirement (only I'm changing visibility, not the Enabled property). The following code segment, should however work the same for either property. For me the key is to apply the settings in the "Opened" event, notthe "Opening" event. Let me know if it helps.


1 PrivateSubTransactionContextMenu_Opened(ByValsenderAsSystem.Object,ByValeAsSystem.EventArgs)HandlesTransactionContextMenu.Opened
2 'FilterorUnfilter
3 If(Me.assetIdFilterIsNothing)Then
4 Me.FilterByThisAssetToolStripMenuItem.Visible=True
5 Me.RemoveAssetIdFilterToolStripMenuItem.Visible=False
6 Else
7 Me.FilterByThisAssetToolStripMenuItem.Visible=False
8 Me.RemoveAssetIdFilterToolStripMenuItem.Visible=True
9 EndIf
10 EndSub
Jordan At Kawa  Wednesday, March 04, 2009 12:28 AM
Hi,

I'm just throwing my 2 cents in, hoping it will be helpfull.

I had a similar requirement (only I'm changing visibility, not the Enabled property). The following code segment, should however work the same for either property. For me the key is to apply the settings in the "Opened" event, notthe "Opening" event. Let me know if it helps.


1 PrivateSubTransactionContextMenu_Opened(ByValsenderAsSystem.Object,ByValeAsSystem.EventArgs)HandlesTransactionContextMenu.Opened
2 'FilterorUnfilter
3 If(Me.assetIdFilterIsNothing)Then
4 Me.FilterByThisAssetToolStripMenuItem.Visible=True
5 Me.RemoveAssetIdFilterToolStripMenuItem.Visible=False
6 Else
7 Me.FilterByThisAssetToolStripMenuItem.Visible=False
8 Me.RemoveAssetIdFilterToolStripMenuItem.Visible=True
9 EndIf
10 EndSub
Jordan At Kawa  Wednesday, March 04, 2009 12:28 AM
Thanks for your reply..I allready resolved it by handling the RowContextMenuStripNeeded for the DataGridView..I assign there the ContextMenuStrip property of args parameter..here is the enabled/disabled logic..
Thanks anyway for responding
emarinescu  Thursday, March 05, 2009 12:46 PM
i have the same trouble as yours,can you please tell me more details about how you solve this problem。�
some code will be best...thanks
yeng25  Tuesday, September 29, 2009 6:10 AM

You can use google to search for other answers

Custom Search

More Threads

• How to Fetch Record from DataAdapter?
• Complex SQL statement..
• Error updating data from DataGridView data source
• website validation
• rowfilter by month
• How to know the parent row index of a cell in Data Grid View?
• How to Trap Enterkey in DataGridView control in VB.Net
• Binding to an SQL Database Column
• Interfaces in C#.net
• Help set the focus on the label's control