473,385 Members | 1,824 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,385 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 2986
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...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
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?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.