Context Menu in a ListView

Hello,
I'm trying to develop my own Explorer for PocketPC, I'm getting stucked with ContextMenu... here's my problem.
I've a default ContextMenu, called contextMenu1 with field as refresh,paste,paste link and so on, and a file related one, called itemMenu that has field as "copy","cut","properties", and so on....

using the itemActivate event, I set the CM to the listview, with this code


private void item_Selected(object sender, System.EventArgs e)

{

try

{

String tmpPath = CurrentPath;

ListViewItem currentItem = this.listView1.FocusedItem;

currentItem.ListView.ContextMenu = itemMenu;

....

 


My questions are :

1)Activate event isn't the best event I think,since I've to click on "file" for opening, is there a better event
2)How do I reset the ContextMenu to default one when no item is selected and in this case, which event have I to process

Thanks in advance
Paolo

p.s. I'm working with cf 1.1


Answer this question

Context Menu in a ListView

  • Robert E. Spivack

    wow, you've solved almost all of my problems, thanks a lot Daniel!!!
    I've created a delegate for item_Selected that only does context menu related stuff and item_Activated for item's manipulation... now I go on coding, thanks you a lot

    Bests
    Paolo

    p.s. I've seen that CF 1.0 doesn't support multiple row selection, do you know if there's a workaround to that Thanks again for your help

  • fulgerica

    1. There is no cf1.1. Only cf 1.0 and cf 2.0 Beta

    2. Since you have the reference to the listview (listView1) why don't you use it directly for assigning the contextmenu and you go via a listviewitem

    3. You should use the SelectedItem, not the focused item

    4. You can get the selected item with a call like this:
    listView1.Items[listView1.SelectedIndices[0]]

    5. Before you do the above, you must check that there are selected items (and this answers your other question too):
    if (listView1.SelectedIndices.Count > 0) {...}

    6. A better event to use is the SelectedIndex event. A gotcha: every time the user changes items, the event will fire twice, once with no item selected and once with the item the user just selected.

    Cheers
    Daniel



  • Context Menu in a ListView