Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
4970
How to get the row in xamgrid for rightclick for contextmenu?
posted

I have set contextmenu for xamgrid like:

<XamGrid     ItemsSource="{Binding MyList, Mode=TwoWay}">
<ig:ContextMenuService.Manager>
    <ig:ContextMenuManager ModifierKeys="None" OpenMode="RightClick" >
        <ig:ContextMenuManager.ContextMenu>
            <ig:XamContextMenu Opening="XamContextMenu_Opening">
                <ig:XamContextMenu.ItemTemplate>
        <DataTemplate>
            <StackPanel Orientation="Horizontal">
                <CheckBox Click="CheckBox_Click"  Tag="{Binding ID}" IsChecked="{Binding IsChecked, Mode=TwoWay}" />
                <TextBlock Text="{Binding MyName}" Margin="5,0,0,0"/>
            </StackPanel>
        </DataTemplate>
                </ig:XamContextMenu.ItemTemplate>
            </ig:XamContextMenu>
        </ig:ContextMenuManager.ContextMenu>
    </ig:ContextMenuManager>
</ig:ContextMenuService.Manager>
<ig:XamGrid.Columns>
.....
</ig:XamGrid.Columns>
</XamGrid>

there is a checkbox in side the contextmenu. then in Click event handler for this checkbox, I want to know the specific row of xamgrid when rightclick  hit on it. How can I do it in code for checkbox Click event handler?

right now, I need to click the row firstly, then rightclick on the row for contextmenu, then I get the row from selected row.  This is not user friendly. So I want to one right click for all.

 

 

Parents
  • 6475
    Suggested Answer
    posted

    Hi,

    You could store a reference to the clicked row when the context menu is being opened.

    Your code should look something like this:

    private void XamContextMenu_Opening(object sender, Infragistics.Controls.Menus.OpeningEventArgs e)
    {
        Row row = (from x in e.GetClickedElements<CellsPanel>()
                   select x.Row).FirstOrDefault() as Row;
    
        // Discard displaying the context menu when not clicking on data rows:
        if (row == null || row.RowType != RowType.DataRow)
        {
            e.Cancel = true;
        }
    }
    
    
    
    Hope this helps,
Reply Children