PopupMenu in ListView ONLY when item selected !!?

Hi,

I use Borland C++ Builder 4

In my app I have a ListView with x items.
I have associated a PopupWindow with the ListView.  So when Right-Mouse button is pressed, The PopupWindow appears.
However,
This happens whether an item in the ListView is selected or not !!
Can I do this selectively ...
ONLY Popup when Item IS selected !!??

Hope someone can help !?
Thanks,
Peter
sneeuwAsked:
Who is Participating?
 
cyber13Connect With a Mentor Commented:
//---------------------------------------------------------------------------
void __fastcall TForm::ListViewMouseDown(TObject *Sender,
      TMouseButton Button, TShiftState Shift, int X, int Y)
{
if (ListView->SelCount > 0 && Button == mbRight)
        {
        // Item is selected with right mouse-button
        PopupMenu->Popup(Form->Left + ListView->Left + X, Form->Top + ListView->Top + Y) ;
            
            // Selected item is :
            TListItem *ListItem = ListView->Selected ;
            //
        }
}
//---------------------------------------------------------------------------
0
 
SmallGodCommented:
I am not really familiar with Borland C++ Builder, so I can't give you specific code, but I'll take a shot at it.  I assume your code allows a means for identifying the currently selected item, or that no item is selected, in the listview.  As long as this is the case, the function that handles the right mouse click needs to check that the item is selected, and only display the PopupWindow if the item is selected.
 
0
 
sneeuwAuthor Commented:
I agree, but (unless I was drunk again ;-) I dont think ListView has an Event that returns the Mouse button that was clicked ???
0
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
MichaelSCommented:
There is. NM_RCLICK notification message. Just check if there are selected items ListView_GetSelectedCount() or send directly LVM_GETSELECTEDCOUNT message for it and show menu if it returns more then 0.
0
 
sneeuwAuthor Commented:
I am afraid I never captured messages myself.  How would I go about writing an event that triggers when the right mouse button is clicked on the Listview ??
(Checking the selection is then easy).
0
 
sneeuwAuthor Commented:
Increased points a bit
0
 
MichaelSCommented:
You have to capture WM_NOTIFY message and check the

((LPNMHDR)lParam)->code == NM_RCLICK

I am not working in BCPPB, sorry.
0
 
SmallGodCommented:
What function displays the popup window?  At the beging of that function, simply check to see if listview has any selected items, before displaying the popup wundow.  I just assumed this would be in a right click handler as the right click is what bring up the popup menu.  No need to make it more complicated, and it doesn't neccesarily have to be done through the capture process.
BTW  SmallGod will no longer be responding to any threads, even this one.  I will still be watching, and may post further info under a different login name.
0
 
sneeuwAuthor Commented:
The problem is that this object's OnClick Event Handler doesn't pass the mouse button which was clicked !!
0
 
MichaelSCommented:
Which object?
0
 
sneeuwAuthor Commented:
TListView
0
 
MichaelSCommented:
Few words about PopupWindow?
0
 
sneeuwAuthor Commented:
A TPopupMenu object

(Sorry for the confusion Menu <-> Window).
0
 
sneeuwAuthor Commented:
Ahaaaaaaaaaaaaa
0
All Courses

From novice to tech pro — start learning today.