Bob Gatto

Bob Gatto

  • NA
  • 44
  • 8.3k

Display a Context Menu only in certain clicked columns of a data grid

Sep 5 2023 7:13 PM

I have a Syncfusion datagrid control and I've included in it a CellRightTapped event and a FlyoutBase.ContextFlyout menu within the control. Now I'm having the CellRightTapped event code run only if column 3 is clicked.

So what I'm trying to figure out is how do I NOT have the context menu appear if column 3 is right-clicked.

Here is the XAML code that I have:

<sf:SfDataGrid x:Name="PasswdVw" Grid.Row="2" Grid.Column="2" Grid.RowSpan="2"
    ItemsSource="{Binding PassWrd}" SelectedRow="{Binding SelPassRws, Mode=TwoWay}">
   <FlyoutBase.ContextFlyout>
      <MenuFlyout>
         <MenuFlyoutItem Text="Copy User Name" Clicked="MenuFlyoutItem_Clicked"
          CommandParameter="UsrName"/>
         <MenuFlyoutItem Text="Copy Password" Clicked="MenuFlyoutItem_Clicked"
          CommandParameter="Passwd"/>
         <MenuFlyoutItem Text="Go To Web Site" Clicked="MenuFlyoutItem_Clicked"
          CommandParameter="WebSite"/>
         </MenuFlyout>
        </FlyoutBase.ContextFlyout>
        <sf:SfDataGrid.DefaultStyle>
            <sf:DataGridStyle RowBackground="white" SelectedRowTextColor="White"
            SelectionBackground="blue" HeaderRowBackground="#C5C5C5"
            HeaderRowTextColor="Black" HeaderRowFontAttributes="Bold"/>
        </sf:SfDataGrid.DefaultStyle>
        <sf:SfDataGrid.Columns>
            <sf:DataGridTextColumn MappingName="PassId" Visible="False"/>
            <sf:DataGridTemplateColumn MappingName="PassTitle" HeaderText="Title"
              CellPadding="10" HeaderTextAlignment="Center"  ColumnWidthMode="FitByCell">
            <sf:DataGridTemplateColumn.CellTemplate>
               <DataTemplate>
                 <local:HyperlinkLabel Text="{Binding PassTitle}"
                     BackgroundColor="White"
                     Url="{Binding PassUrl}" VerticalOptions="Center"/>
                 </DataTemplate>
               </sf:DataGridTemplateColumn.CellTemplate>
            </sf:DataGridTemplateColumn>
            <sf:DataGridTextColumn MappingName="PassUsrname" HeaderText="User Name"
               HeaderTextAlignment="Center" ColumnWidthMode="FitByCell"/>
            <sf:DataGridTextColumn MappingName="PassPassword" HeaderText="Password"
               HeaderTextAlignment="Center" Width="200"/>
            <sf:DataGridTextColumn MappingName="PassUrl" Visible="False"/>
            <sf:DataGridTextColumn MappingName="PassGrpName" HeaderText="Group"
               HeaderTextAlignment="Center" ColumnWidthMode="FitByCell"/>
            <sf:DataGridTextColumn MappingName="PassNotes" HeaderText="Notes" Width="100"
               HeaderTextAlignment="Center"/>
        </sf:SfDataGrid.Columns>
    </sf:SfDataGrid>

I would appreciate someone's help.

Thanks.


Answers (1)