Ticket T241255
Visible to All Users

Don't display context menu on right click on group row

created 10 years ago

Hi,

I have redefined a context menu for my grid's elements like this :

XAML
<dxg:TableView.ContextMenu> <ContextMenu Visibility="{Binding CurrentMessage,Converter={StaticResource NullToVisibilityConverter}, ConverterParameter=1}"> <MenuItem Header="Répondre" Command="{Binding AnswerCommand}" CommandParameter="ANSWER"/> <MenuItem Header="Répondre à tous" Command="{Binding AnswerCommand}" CommandParameter="ANSWER_TO_ALL"/> <MenuItem Header="Transférer" Command="{Binding AnswerCommand}" CommandParameter="TRANSFER"/> <Separator/> <MenuItem Header="Supprimer" Command="{Binding DeleteMailCommand}" CommandParameter="ANSWER"/> <MenuItem Header="Marquer comme non lu" Command="{Binding MarkAsUnreadCommand}"/> <Separator/> <MenuItem Header="Enregistrer la pièce jointe" Visibility="{Binding CurrentMessage.HasAttachment, Converter={StaticResource BooleanToVisibilityConverter}, ConverterParameter=1}"> <MenuItem Header="Dans le dossier patient" Command="{Binding SaveAttachmentCommand}" CommandParameter="True"/> <MenuItem Header="Enregistrer sous ..." Command="{Binding SaveAttachmentCommand}" CommandParameter="False"/> </MenuItem> <MenuItem Header="Enregistrer le mail" Command="{Binding SaveMailCommand}"/> <!--<Separator/>--> <!--<MenuItem Header="Imprimer" Command="{Binding PrintCommand}"/>--> </ContextMenu> </dxg:TableView.ContextMenu>

It works great. BUt, I don't want this menu to be displayed on group rows (this is why Visibility of menu is set to the currentMessage, which is the currentItem, and NullToVisibilityConverter prevents menu to appear if no message selected).
If I right click on group row, nothing shows up, which is want I want. But when I select a message by left-clicking on it, the contextMenu shows up (passing throught converter).

Is there a simple and effective way to prevents showing my custom context menu on group rows ?

Thanks

Show previous comments (2)
Andrey Marten (DevExpress Support) 10 years ago

    Hello Christophe,

    In this case, I suggest you handle the TableView.ContextMenuOpening event and call the TableView.CalcHitInfo(Point) method to get information about an element in GridControl that is clicked. Set the ContextMenuEventArgs.Handled property to True if the GridViewHitInfoBase.InRow property is True and the result of GridControl's method with the GridViewHitInfoBase.RowHandle property value as a parameter returns False.
    I've created a simple sample to illustrate the main idea of the approach. Is it suitable for you?

    Thanks,
    Andrey

      Hi Andrey,
      Yes, exactly. Thank you.

      Andrey Marten (DevExpress Support) 10 years ago

        I'm happy to hear that my assistance was helpful. I've posted an answer with a short description of the main idea of the approach to allow other customers that might have the same requirements to find this information more easily.
        Please do not hesitate to contact us if you have any further questions.
        Andrey

        Answers approved by DevExpress Support

        created 10 years ago (modified 10 years ago)

        Hello,

        When it's required to prevent ContextMenu from being opened depending on which visual element is clicked in GridControl, the corresponding logic can be placed to the TableView.ContextMenuOpening event handler. Call there the TableView.CalcHitInfo(Point) method to get information about an element in GridControl that is clicked and set the ContextMenuEventArgs.Handled property to True if the context menu should not be opened. I've created a simple sample to illustrate the main idea of the approach.

        Thanks,
        Andrey

          Disclaimer: The information provided on DevExpress.com and affiliated web properties (including the DevExpress Support Center) is provided "as is" without warranty of any kind. Developer Express Inc disclaims all warranties, either express or implied, including the warranties of merchantability and fitness for a particular purpose. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.

          Confidential Information: Developer Express Inc does not wish to receive, will not act to procure, nor will it solicit, confidential or proprietary materials and information from you through the DevExpress Support Center or its web properties. Any and all materials or information divulged during chats, email communications, online discussions, Support Center tickets, or made available to Developer Express Inc in any manner will be deemed NOT to be confidential by Developer Express Inc. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.