473,386 Members | 1,873 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

ContextMenu

Hi,
I am trying to show the shortcut menu on a richtextbox control by
adding the contextmenu component onto the form. The richtextbox
property is assigned to the contextmenu. I created my shorcuts, copy,
paste, etc. However, on the form I have a datagrid
which is also assigned to the same contextmenu and contextmenupopup
event as follows:
....
If ContextMenu1.SourceControl Is richtextbox1Then
' Add MenuItems to display for the TextBox.
ContextMenu1.MenuItems.Add(menuItem1)
ContextMenu1.MenuItems.Add(menuItem2)
ElseIf ContextMenu1.SourceControl Is datagrid1 Then
' Add the MenuItem
ContextMenu1.MenuItems.Add(menuItem3)
End If
....
when I right-click on the richtext control I get the sourcecontrol =
Nothing, but r-click on grid
i get the control name. I droped the richtext control and added another
one and set the
cmenu property and still nothing. Any idea?

Thanks in advance

Aug 16 '06 #1
7 2185
Need some more code, like the event handler sub declaration and what it
handles.
--
Dennis in Houston
"wandii" wrote:
Hi,
I am trying to show the shortcut menu on a richtextbox control by
adding the contextmenu component onto the form. The richtextbox
property is assigned to the contextmenu. I created my shorcuts, copy,
paste, etc. However, on the form I have a datagrid
which is also assigned to the same contextmenu and contextmenupopup
event as follows:
....
If ContextMenu1.SourceControl Is richtextbox1Then
' Add MenuItems to display for the TextBox.
ContextMenu1.MenuItems.Add(menuItem1)
ContextMenu1.MenuItems.Add(menuItem2)
ElseIf ContextMenu1.SourceControl Is datagrid1 Then
' Add the MenuItem
ContextMenu1.MenuItems.Add(menuItem3)
End If
....
when I right-click on the richtext control I get the sourcecontrol =
Nothing, but r-click on grid
i get the control name. I droped the richtext control and added another
one and set the
cmenu property and still nothing. Any idea?

Thanks in advance

Aug 16 '06 #2

Dennis wrote:
Need some more code, like the event handler sub declaration and what it
handles.
--
Dennis in Houston
"wandii" wrote:
Hi,
I am trying to show the shortcut menu on a richtextbox control by
adding the contextmenu component onto the form. The richtextbox
property is assigned to the contextmenu. I created my shorcuts, copy,
paste, etc. However, on the form I have a datagrid
which is also assigned to the same contextmenu and contextmenupopup
event as follows:
....
If ContextMenu1.SourceControl Is richtextbox1Then
' Add MenuItems to display for the TextBox.
ContextMenu1.MenuItems.Add(menuItem1)
ContextMenu1.MenuItems.Add(menuItem2)
ElseIf ContextMenu1.SourceControl Is datagrid1 Then
' Add the MenuItem
ContextMenu1.MenuItems.Add(menuItem3)
End If
....
when I right-click on the richtext control I get the sourcecontrol =
Nothing, but r-click on grid
i get the control name. I droped the richtext control and added another
one and set the
cmenu property and still nothing. Any idea?

Thanks in advance
Thanks for your time Dennis. Here you go... I have the property of
datagrid and richtext
are assigned to contextmenu. Works fine for the datagrid and I get
nothing for the rtext. Thanks

Public Sub ContextMenu1_Popup(ByVal sender As System.Object, ByVal
e As System.EventArgs) Handles ContextMenu1.Popup

' Define the MenuItem objects to display for the TextBox.
Dim menuItem1 As New MenuItem("&Copy")
Dim menuItem2 As New MenuItem("&Find and Replace")
' Define the MenuItem object to display for the PictureBox.
Dim menuItem3 As New MenuItem("C&hange Picture")

' Clear all previously added MenuItems.
ContextMenu1.MenuItems.Clear()

If ContextMenu1.SourceControl Is richtextbox1Then
' Add MenuItems to display for the TextBox.
ContextMenu1.MenuItems.Add(menuItem1)
ContextMenu1.MenuItems.Add(menuItem2)
ElseIf ContextMenu1.SourceControl Is datagrid1 Then
' Add the MenuItem to display for the PictureBox.
ContextMenu1.MenuItems.Add(menuItem3)
End If

Aug 17 '06 #3
Your code looks fine. Are you able to type information into the richtextbox
to be sure it can get the focus? Also, does the contextmenu1 appear when you
right click on the richtextbox?
--
Dennis in Houston
"wandii" wrote:
>
Dennis wrote:
Need some more code, like the event handler sub declaration and what it
handles.
--
Dennis in Houston
"wandii" wrote:
Hi,
I am trying to show the shortcut menu on a richtextbox control by
adding the contextmenu component onto the form. The richtextbox
property is assigned to the contextmenu. I created my shorcuts, copy,
paste, etc. However, on the form I have a datagrid
which is also assigned to the same contextmenu and contextmenupopup
event as follows:
....
If ContextMenu1.SourceControl Is richtextbox1Then
' Add MenuItems to display for the TextBox.
ContextMenu1.MenuItems.Add(menuItem1)
ContextMenu1.MenuItems.Add(menuItem2)
ElseIf ContextMenu1.SourceControl Is datagrid1 Then
' Add the MenuItem
ContextMenu1.MenuItems.Add(menuItem3)
End If
....
when I right-click on the richtext control I get the sourcecontrol =
Nothing, but r-click on grid
i get the control name. I droped the richtext control and added another
one and set the
cmenu property and still nothing. Any idea?
>
Thanks in advance
>
>

Thanks for your time Dennis. Here you go... I have the property of
datagrid and richtext
are assigned to contextmenu. Works fine for the datagrid and I get
nothing for the rtext. Thanks

Public Sub ContextMenu1_Popup(ByVal sender As System.Object, ByVal
e As System.EventArgs) Handles ContextMenu1.Popup

' Define the MenuItem objects to display for the TextBox.
Dim menuItem1 As New MenuItem("&Copy")
Dim menuItem2 As New MenuItem("&Find and Replace")
' Define the MenuItem object to display for the PictureBox.
Dim menuItem3 As New MenuItem("C&hange Picture")

' Clear all previously added MenuItems.
ContextMenu1.MenuItems.Clear()

If ContextMenu1.SourceControl Is richtextbox1Then
' Add MenuItems to display for the TextBox.
ContextMenu1.MenuItems.Add(menuItem1)
ContextMenu1.MenuItems.Add(menuItem2)
ElseIf ContextMenu1.SourceControl Is datagrid1 Then
' Add the MenuItem to display for the PictureBox.
ContextMenu1.MenuItems.Add(menuItem3)
End If

Aug 18 '06 #4
Sorry Dennis I could not get back to you soon. Yes I tried to setfocus
to richtext on form load and can type into richtext, however, no
contextmenu appears when I r-click on
it. I put a breakpoint please see below:
bp If ContextMenu1.SourceControl Is richtextbox1Then
' Add MenuItems to display for the TextBox.
ContextMenu1.MenuItems.Add(menuItem1)
ContextMenu1.MenuItems.Add(menuItem2)
ElseIf ContextMenu1.SourceControl Is datagrid1 Then
' Add the MenuItem
ContextMenu1.MenuItems.Add(menuItem3)
End If
and sourcecontrol is nothing. Plan B: deleted the old richtext control
and added a new one still sourcecontrol is nothing. I tried on a
button, datagrid and sourcecontrol is not
null. Richtext's contextmenu property is to the contextmenu2. This is
very strange?
I am not sure if I need to set another property. Any other
suggestions. Thanks
Dennis wrote:
Your code looks fine. Are you able to type information into the richtextbox
to be sure it can get the focus? Also, does the contextmenu1 appear when you
right click on the richtextbox?
--
Dennis in Houston
"wandii" wrote:

Dennis wrote:
Need some more code, like the event handler sub declaration and what it
handles.
--
Dennis in Houston
>
>
"wandii" wrote:
>
Hi,
I am trying to show the shortcut menu on a richtextbox control by
adding the contextmenu component onto the form. The richtextbox
property is assigned to the contextmenu. I created my shorcuts, copy,
paste, etc. However, on the form I have a datagrid
which is also assigned to the same contextmenu and contextmenupopup
event as follows:
....
If ContextMenu1.SourceControl Is richtextbox1Then
' Add MenuItems to display for the TextBox.
ContextMenu1.MenuItems.Add(menuItem1)
ContextMenu1.MenuItems.Add(menuItem2)
ElseIf ContextMenu1.SourceControl Is datagrid1 Then
' Add the MenuItem
ContextMenu1.MenuItems.Add(menuItem3)
End If
....
when I right-click on the richtext control I get the sourcecontrol =
Nothing, but r-click on grid
i get the control name. I droped the richtext control and added another
one and set the
cmenu property and still nothing. Any idea?

Thanks in advance
Thanks for your time Dennis. Here you go... I have the property of
datagrid and richtext
are assigned to contextmenu. Works fine for the datagrid and I get
nothing for the rtext. Thanks

Public Sub ContextMenu1_Popup(ByVal sender As System.Object, ByVal
e As System.EventArgs) Handles ContextMenu1.Popup

' Define the MenuItem objects to display for the TextBox.
Dim menuItem1 As New MenuItem("&Copy")
Dim menuItem2 As New MenuItem("&Find and Replace")
' Define the MenuItem object to display for the PictureBox.
Dim menuItem3 As New MenuItem("C&hange Picture")

' Clear all previously added MenuItems.
ContextMenu1.MenuItems.Clear()

If ContextMenu1.SourceControl Is richtextbox1Then
' Add MenuItems to display for the TextBox.
ContextMenu1.MenuItems.Add(menuItem1)
ContextMenu1.MenuItems.Add(menuItem2)
ElseIf ContextMenu1.SourceControl Is datagrid1 Then
' Add the MenuItem to display for the PictureBox.
ContextMenu1.MenuItems.Add(menuItem3)
End If
Sep 2 '06 #5
Try this code (note the "sender" in the if statments:
Public Sub ContextMenu1_Popup(ByVal sender As System.Object, ByVal _
e As System.EventArgs) Handles ContextMenu1.Popup

' Define the MenuItem objects to display for the TextBox.
Dim menuItem1 As New MenuItem("&Copy")
Dim menuItem2 As New MenuItem("&Find and Replace")
' Define the MenuItem object to display for the PictureBox.
Dim menuItem3 As New MenuItem("C&hange Picture")

' Clear all previously added MenuItems.
ContextMenu1.MenuItems.Clear()

If Sender Is richtextbox1Then
' Add MenuItems to display for the TextBox.
ContextMenu1.MenuItems.Add(menuItem1)
ContextMenu1.MenuItems.Add(menuItem2)
ElseIf Sender Is datagrid1 Then
' Add the MenuItem to display for the PictureBox.
ContextMenu1.MenuItems.Add(menuItem3)
End If

--
Dennis in Houston

Sep 3 '06 #6
Nope - didn't work. The reason is that the sender listed below is
looking at the contextmenu (1, 2, ...) controls.
Dennis wrote:
Try this code (note the "sender" in the if statments:
Public Sub ContextMenu1_Popup(ByVal sender As System.Object, ByVal _
e As System.EventArgs) Handles ContextMenu1.Popup

' Define the MenuItem objects to display for the TextBox.
Dim menuItem1 As New MenuItem("&Copy")
Dim menuItem2 As New MenuItem("&Find and Replace")
' Define the MenuItem object to display for the PictureBox.
Dim menuItem3 As New MenuItem("C&hange Picture")

' Clear all previously added MenuItems.
ContextMenu1.MenuItems.Clear()

If Sender Is richtextbox1Then
' Add MenuItems to display for the TextBox.
ContextMenu1.MenuItems.Add(menuItem1)
ContextMenu1.MenuItems.Add(menuItem2)
ElseIf Sender Is datagrid1 Then
' Add the MenuItem to display for the PictureBox.
ContextMenu1.MenuItems.Add(menuItem3)
End If

--
Dennis in Houston
Sep 5 '06 #7
Sorry, I don't know what to try next. Are you sure you spelled the name of
the richtext box correctly? You might want to add a second contextmenu
dedicated to your richtextbox.
--
Dennis in Houston
"wandii" wrote:
Nope - didn't work. The reason is that the sender listed below is
looking at the contextmenu (1, 2, ...) controls.
Dennis wrote:
Try this code (note the "sender" in the if statments:
Public Sub ContextMenu1_Popup(ByVal sender As System.Object, ByVal _
e As System.EventArgs) Handles ContextMenu1.Popup

' Define the MenuItem objects to display for the TextBox.
Dim menuItem1 As New MenuItem("&Copy")
Dim menuItem2 As New MenuItem("&Find and Replace")
' Define the MenuItem object to display for the PictureBox.
Dim menuItem3 As New MenuItem("C&hange Picture")

' Clear all previously added MenuItems.
ContextMenu1.MenuItems.Clear()

If Sender Is richtextbox1Then
' Add MenuItems to display for the TextBox.
ContextMenu1.MenuItems.Add(menuItem1)
ContextMenu1.MenuItems.Add(menuItem2)
ElseIf Sender Is datagrid1 Then
' Add the MenuItem to display for the PictureBox.
ContextMenu1.MenuItems.Add(menuItem3)
End If

--
Dennis in Houston

Sep 5 '06 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: MD | last post by:
I have a ContextMenu that is assigned to 3 RichTextBox's (i.e., if you right-click on any of the 3 RichTextBox's, you get the same ContextMenu). My ContextMenu has 2 items, each of which have their...
2
by: Derrick | last post by:
I've been working on an application which has a NotifyIcon (system tray icon), and a corresponding ContextMenu. I want to be able to update this menu dynamically. However, when I make changes to...
2
by: Zieben | last post by:
Hello! I have such problem! I have my UserControl. I override property ContextMenu for this Control as ..... new ContextMenu ContextMenu{ set {_contextMenu = value;}
0
by: cemino | last post by:
Hi, I got a problem with ContextMenu. I'm using a hot-key (like Ctrl-B) to show contextMenu in my program. Things is like below: contextMenu.Show(Form1, New...
10
by: tmaster | last post by:
When I try to dynamically add a second sub menu item to this ContextMenu item, I get an error 'Specified argument was out of the range of valid values'. Private Sub mnuTopics_Show_Select(ByVal...
7
by: TryingLikeHeck | last post by:
I have a usercontrol on which I've generated a context menu in designer. The properties of the control lists for ContextMenu (none) The menu shows up in the designer window and I can edit it To...
11
by: Graham Charles | last post by:
I'm writing a control inheriting from ComboBox, and I'd like to add an entry to the ContextMenu for that combo box. I have no problem if I create an entirely new ContextMenu from scratch, but I'd...
3
by: Libby Sharf | last post by:
Hello, I have several ContextMenus and I want to connect them to the GridControl's ContextMenu property depending on the row that was right clicked. Is there an event that is raised just before...
0
by: Steve Richter | last post by:
I cant get a contextmenu to popup in the context of a datagridview. It pops up in the ListBox, and in the form itself. But not the DataGridView. How could that be? here is my code: using...
3
by: asharda | last post by:
Hi, I am trying to create a context menu in my application. The context menu takes menu otems from an XML file. In XAML the code is <Grid.ContextMenu> <ContextMenu Name="cm" StaysOpen="true"...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.