views:

381

answers:

2

Hi

I have a MenuItem that contains all files in a spesific folder.

The menuitem is populated on its own Popup event (using System.IO.Directory.GetFiles), but if it is too close to the lower right corner of the screen (or so it seems), it will jump higher up on the screen while being populated.

If I populate it before the Popup event is raised, the menuitem will open in the usual position.

I must populate it on the popup event to keep the contents of the folder up-to-date.

Why does the menuitem jump if it is populated on the Popup event, and how can I avoid it?

A: 

After thinking about this a little, I'm not sure updating the menu at popup time is the best approach. Build the menu once at startup, and use a FileSystemWatcher (or a few if there are different locations) to notify you of changes, and update the menu as necessary.

JimG
A: 

I had the same problem with a DataGridView.

I used pop-up menu to let the user choose from few most typical inputs when filling up the grid. And depending on what was in the cell clicked, options would be a bit different. I had this context menu jumping and blinking. I tried several approaches, what I finally did was

1. resetting the ContextMenu property of my DataGridView (I mean I just zeroed this property)

2. populating the menu in DataGridView's CellMouseDown event instead of the context menu's Opening event

3. after populating it (still in CellMouseDown), simply assigning this menu to this particular cell

myDataGridView[column, row].ContextMenuStrip = myPopUpMenu;

And that's it. Worked fine, without any undesired visual phenomena ;).

Vibo