473,233 Members | 2,284 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,233 software developers and data experts.

Context Menu problem

Hi all,

Lately I have been working on an application in VB .net CF for Pocket PC
device. I have a small question about Context Menu.

When I try to close the window after context menu is poped up, the window
does not closes until I click on the window. Below is the code. Hopefully,
you can help me out.
Friend WithEvents ContextMenu1 As System.Windows.Forms.ContextMenu
-----Remember ContextMenu1 has no menu items added.---------
'Setting context menu for the listview. When user holds the mouse on the
listview item, then context menu pop up event is fired. Look below to see the
code
Me.ListView1.ContextMenu = Me.ContextMenu1

Private Sub ContextMenu1_Popup(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles ContextMenu1.Popup
Me.Close() 'The window does not closes. Don't know why
End Sub

Your help will be appreciated
Jul 21 '05 #1
4 2954
Mohit:

I'm not sure I follow what you're trying to do. Popup is triggered right
before the menu is shown. As such, why would you want to close the form
it's based on before it's shown - nothing could be selected if you could
successfully close it. If you do it successfully I'm pretty cure you're
going to raise an exception - b/c you can't access a disposed object. You
don't know for sure exactly the sequence that will fire but close is going
to call dispose so the sender won't exist.

--
W.G. Ryan MVP (Windows Embedded)

TiBA Solutions
www.tibasolutions.com | www.devbuzz.com | www.knowdotnet.com
"Mohit Gupta" <Mo********@discussions.microsoft.com> wrote in message
news:34**********************************@microsof t.com...
Hi all,

Lately I have been working on an application in VB .net CF for Pocket PC
device. I have a small question about Context Menu.

When I try to close the window after context menu is poped up, the window
does not closes until I click on the window. Below is the code. Hopefully,
you can help me out.
Friend WithEvents ContextMenu1 As System.Windows.Forms.ContextMenu
-----Remember ContextMenu1 has no menu items added.---------
'Setting context menu for the listview. When user holds the mouse on the listview item, then context menu pop up event is fired. Look below to see the code
Me.ListView1.ContextMenu = Me.ContextMenu1

Private Sub ContextMenu1_Popup(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ContextMenu1.Popup
Me.Close() 'The window does not closes. Don't know why
End Sub

Your help will be appreciated

Jul 21 '05 #2
HI Ryan

Actually, let me explain what I am doing.

THere is a LISTVIEW object in an application that has, for example, 10 rows.
Now, as I am developing on .NET CF framework, which in other words means an
applicaiton is developed for Pocket PC. Therefore, what I want to do is to
hold the stylus on to the item until context menu popup event is fired.

For that reason I created a new ContextMenu object having no menu items in
it. I assigned this context menu to LISTVIEW object. Without any problems,
context menu popup is fired when I hold my stylus for longer period of time
on the selected item.

For more information, every item has an ID associated (in this example) with
it. When an item is selected and context menu pop up is fired, I pass that ID
to the next form that I show as a dialog box. Once the form dialog if closed,
I come back to my context menu popup function and want to close the parent
window. But when I try to close it nothing happens until stylus touches the
screen.

Bit for more code
Private Sub ContextMenu1_Popup(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles ContextMenu1.Popup
Dim formObj As New Form2
formObj.setValues(ListView1.selectedItem(0).text)
formObj.showDialog() 'Perform some task and close it
'After the dialog form is closed, close this window as well.
Me.Close() 'The window does not closes. Don't know why
End Sub

I think now you have more idea of what I am trying to do. Definitely there
is another way, if you are thinking about it, for example, have a button and
perform the same task when the button is clicked. I have already been
successful that way but I want to resolve the above mentioned issue.

"W.G. Ryan eMVP" wrote:
Mohit:

I'm not sure I follow what you're trying to do. Popup is triggered right
before the menu is shown. As such, why would you want to close the form
it's based on before it's shown - nothing could be selected if you could
successfully close it. If you do it successfully I'm pretty cure you're
going to raise an exception - b/c you can't access a disposed object. You
don't know for sure exactly the sequence that will fire but close is going
to call dispose so the sender won't exist.

--
W.G. Ryan MVP (Windows Embedded)

TiBA Solutions
www.tibasolutions.com | www.devbuzz.com | www.knowdotnet.com
"Mohit Gupta" <Mo********@discussions.microsoft.com> wrote in message
news:34**********************************@microsof t.com...
Hi all,

Lately I have been working on an application in VB .net CF for Pocket PC
device. I have a small question about Context Menu.

When I try to close the window after context menu is poped up, the window
does not closes until I click on the window. Below is the code. Hopefully,
you can help me out.
Friend WithEvents ContextMenu1 As System.Windows.Forms.ContextMenu
-----Remember ContextMenu1 has no menu items added.---------
'Setting context menu for the listview. When user holds the mouse on

the
listview item, then context menu pop up event is fired. Look below to see

the
code
Me.ListView1.ContextMenu = Me.ContextMenu1

Private Sub ContextMenu1_Popup(ByVal sender As System.Object, ByVal e

As
System.EventArgs) Handles ContextMenu1.Popup
Me.Close() 'The window does not closes. Don't know why
End Sub

Your help will be appreciated


Jul 21 '05 #3
Ok, so there's something going on in between popup and close...

Anyway, I have form1, Form2 and form3. On form2 I have a listView with an
empty context menu. When form1 loads I declare a new Form2 and show it. On
Popup on Form2 I have the following code:
Dim f3 As New Form3

Select Case f3.ShowDialog

Case DialogResult.OK

Me.Close()

End Select

On Form3 I stuck this behind a button just to get it to close ---

Me.DialogResult = DialogResult.OK

I've run it on my iMATE and a iPAQ 1940 as well as the emulator, it works as
expected each time. You may want to try Application.DoEvents because it's
possible that your screen just isn't refreshing although I doubt it. I
can't seem to replicate the behavior
--
W.G. Ryan MVP (Windows Embedded)

TiBA Solutions
www.tibasolutions.com | www.devbuzz.com | www.knowdotnet.com
"Mohit Gupta" <Mo********@discussions.microsoft.com> wrote in message
news:F3**********************************@microsof t.com...
HI Ryan

Actually, let me explain what I am doing.

THere is a LISTVIEW object in an application that has, for example, 10 rows. Now, as I am developing on .NET CF framework, which in other words means an applicaiton is developed for Pocket PC. Therefore, what I want to do is to
hold the stylus on to the item until context menu popup event is fired.

For that reason I created a new ContextMenu object having no menu items in
it. I assigned this context menu to LISTVIEW object. Without any problems,
context menu popup is fired when I hold my stylus for longer period of time on the selected item.

For more information, every item has an ID associated (in this example) with it. When an item is selected and context menu pop up is fired, I pass that ID to the next form that I show as a dialog box. Once the form dialog if closed, I come back to my context menu popup function and want to close the parent
window. But when I try to close it nothing happens until stylus touches the screen.

Bit for more code
Private Sub ContextMenu1_Popup(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles ContextMenu1.Popup
Dim formObj As New Form2
formObj.setValues(ListView1.selectedItem(0).text)
formObj.showDialog() 'Perform some task and close it
'After the dialog form is closed, close this window as well.
Me.Close() 'The window does not closes. Don't know why
End Sub

I think now you have more idea of what I am trying to do. Definitely there
is another way, if you are thinking about it, for example, have a button and perform the same task when the button is clicked. I have already been
successful that way but I want to resolve the above mentioned issue.

"W.G. Ryan eMVP" wrote:
Mohit:

I'm not sure I follow what you're trying to do. Popup is triggered right before the menu is shown. As such, why would you want to close the form
it's based on before it's shown - nothing could be selected if you could
successfully close it. If you do it successfully I'm pretty cure you're
going to raise an exception - b/c you can't access a disposed object. You don't know for sure exactly the sequence that will fire but close is going to call dispose so the sender won't exist.

--
W.G. Ryan MVP (Windows Embedded)

TiBA Solutions
www.tibasolutions.com | www.devbuzz.com | www.knowdotnet.com
"Mohit Gupta" <Mo********@discussions.microsoft.com> wrote in message
news:34**********************************@microsof t.com...
Hi all,

Lately I have been working on an application in VB .net CF for Pocket PC device. I have a small question about Context Menu.

When I try to close the window after context menu is poped up, the window does not closes until I click on the window. Below is the code. Hopefully, you can help me out.
Friend WithEvents ContextMenu1 As System.Windows.Forms.ContextMenu
-----Remember ContextMenu1 has no menu items added.---------
'Setting context menu for the listview. When user holds the mouse
on the
listview item, then context menu pop up event is fired. Look below to
see the
code
Me.ListView1.ContextMenu = Me.ContextMenu1

Private Sub ContextMenu1_Popup(ByVal sender As System.Object,
ByVal e As
System.EventArgs) Handles ContextMenu1.Popup
Me.Close() 'The window does not closes. Don't know why
End Sub

Your help will be appreciated


Jul 21 '05 #4
Hi Ryan,

I have done the same, but problem still seems to exists. As soon as my
stylus hits the screen, my screen closes. I think my event is still pending.
It resumes when stylus hits the ground. Is there any way to explicity call
the hit of stylus on the screen?

"W.G. Ryan eMVP" wrote:
Ok, so there's something going on in between popup and close...

Anyway, I have form1, Form2 and form3. On form2 I have a listView with an
empty context menu. When form1 loads I declare a new Form2 and show it. On
Popup on Form2 I have the following code:
Dim f3 As New Form3

Select Case f3.ShowDialog

Case DialogResult.OK

Me.Close()

End Select

On Form3 I stuck this behind a button just to get it to close ---

Me.DialogResult = DialogResult.OK

I've run it on my iMATE and a iPAQ 1940 as well as the emulator, it works as
expected each time. You may want to try Application.DoEvents because it's
possible that your screen just isn't refreshing although I doubt it. I
can't seem to replicate the behavior
--
W.G. Ryan MVP (Windows Embedded)

TiBA Solutions
www.tibasolutions.com | www.devbuzz.com | www.knowdotnet.com
"Mohit Gupta" <Mo********@discussions.microsoft.com> wrote in message
news:F3**********************************@microsof t.com...
HI Ryan

Actually, let me explain what I am doing.

THere is a LISTVIEW object in an application that has, for example, 10

rows.
Now, as I am developing on .NET CF framework, which in other words means

an
applicaiton is developed for Pocket PC. Therefore, what I want to do is to
hold the stylus on to the item until context menu popup event is fired.

For that reason I created a new ContextMenu object having no menu items in
it. I assigned this context menu to LISTVIEW object. Without any problems,
context menu popup is fired when I hold my stylus for longer period of

time
on the selected item.

For more information, every item has an ID associated (in this example)

with
it. When an item is selected and context menu pop up is fired, I pass that

ID
to the next form that I show as a dialog box. Once the form dialog if

closed,
I come back to my context menu popup function and want to close the parent
window. But when I try to close it nothing happens until stylus touches

the
screen.

Bit for more code
Private Sub ContextMenu1_Popup(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles ContextMenu1.Popup
Dim formObj As New Form2
formObj.setValues(ListView1.selectedItem(0).text)
formObj.showDialog() 'Perform some task and close it
'After the dialog form is closed, close this window as well.
Me.Close() 'The window does not closes. Don't know why
End Sub

I think now you have more idea of what I am trying to do. Definitely there
is another way, if you are thinking about it, for example, have a button

and
perform the same task when the button is clicked. I have already been
successful that way but I want to resolve the above mentioned issue.

"W.G. Ryan eMVP" wrote:
Mohit:

I'm not sure I follow what you're trying to do. Popup is triggered right before the menu is shown. As such, why would you want to close the form
it's based on before it's shown - nothing could be selected if you could
successfully close it. If you do it successfully I'm pretty cure you're
going to raise an exception - b/c you can't access a disposed object. You don't know for sure exactly the sequence that will fire but close is going to call dispose so the sender won't exist.

--
W.G. Ryan MVP (Windows Embedded)

TiBA Solutions
www.tibasolutions.com | www.devbuzz.com | www.knowdotnet.com
"Mohit Gupta" <Mo********@discussions.microsoft.com> wrote in message
news:34**********************************@microsof t.com...
> Hi all,
>
> Lately I have been working on an application in VB .net CF for Pocket PC > device. I have a small question about Context Menu.
>
> When I try to close the window after context menu is poped up, the window > does not closes until I click on the window. Below is the code. Hopefully, > you can help me out.
>
>
> Friend WithEvents ContextMenu1 As System.Windows.Forms.ContextMenu
> -----Remember ContextMenu1 has no menu items added.---------
> 'Setting context menu for the listview. When user holds the mouse on the
> listview item, then context menu pop up event is fired. Look below to see the
> code
> Me.ListView1.ContextMenu = Me.ContextMenu1
>
> Private Sub ContextMenu1_Popup(ByVal sender As System.Object, ByVal e As
> System.EventArgs) Handles ContextMenu1.Popup
> Me.Close() 'The window does not closes. Don't know why
> End Sub
>
> Your help will be appreciated
>
>


Jul 21 '05 #5

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

Similar topics

3
by: Eddie de Bear | last post by:
Hi, A project I am working on has a requirement for dynamic menus. For the most part this works really well. The menus I'm creating a based on files and directories, so naturally the menu...
8
by: Dennis C. Drumm | last post by:
Is there a way to modify the standard context menu shown when someone right clicks in a windows text box and that would work for all open windows applications? The standard context menu for...
0
by: VP | last post by:
G'day folks, well i am attempting to get an understanding on how to create the menuitems in a context menu on the fly. So far I have managed to actually achieve the menu items being created for...
2
by: Dino M. Buljubasic | last post by:
I have several context menus added to my form. The form is displaying items in listviews connected to the context menus. When I click on an item in a list view, a popup context menu shows allowing...
4
by: Mohit Gupta | last post by:
Hi all, Lately I have been working on an application in VB .net CF for Pocket PC device. I have a small question about Context Menu. When I try to close the window after context menu is poped...
0
by: tony.spalding | last post by:
I'm having a problem trying to add a link to my add-in to a context menu. I'm trying to add it to the context menu that you get when you right click on a stored procedure within the Server...
4
by: Fred | last post by:
Hi, I have a list box with a context menu. When I right click the menu appears as expected. However when I select an option on the context menu the menu does not close. The click event on the...
2
by: MCM | last post by:
I'm working on a plotting control. The plotting control will have a context menu with basic commands for "scaling", "zooming", etc. Is there a way that, from the parent form, I can add more...
3
by: Poggs | last post by:
Hi everyone, I used the pattern for Shell Extensions for Context menu from Dino Esposito's article. However I implemented it in more than one application and it seems that those two right click...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 3 Jan 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). For other local times, please check World Time Buddy In...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...

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.