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?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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
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
Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

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
cyber13Commented:
//---------------------------------------------------------------------------
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
sneeuwAuthor Commented:
Ahaaaaaaaaaaaaa
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C++

From novice to tech pro — start learning today.