Welcome to the Xceed Community | Help
Community Search  
More Search Options

How to limit context menu to display on non selected row in xceed wpf datagrid

Sort Posts: Previous Next
  •  07-02-2009, 9:57 AM Post no. 22219

    How to limit context menu to display on non selected row in xceed wpf datagrid

    Hi,

    I have created a context menu and i want to show that menu on the selected row only.  What happens currently is if i right click on anywhere in grid other than on the selected row still the context menu is displayed.  I dont want that to happen, context menu should only be shown on the selected row, also i want to show context menu on Column header and on particular cell only.

     Also how can we find current cell selected on right click, and set selected row on which its selected.

    Appreiciate a quick response.

    Thanks,

    Raxit

     

     

    Filed under:
  •  07-02-2009, 10:04 AM Post no. 22221 in reply to 22219

    Re: How to limit context menu to display on non selected row in xceed wpf datagrid

    I will assume that you are setting the context menu via a style. In that case, I suggest you add a Trigger to the style that checks the IsSelected property and if its value returns true, then you set the ContextMenu.
    Senior Technical Writer
    - Xceed Software

    In three words I can sum up everything I've learned about life: it goes on.
  •  07-03-2009, 3:19 AM Post no. 22239 in reply to 22221

    Re: How to limit context menu to display on non selected row in xceed wpf datagrid

    Thanks Jenny for quick response. 

    I am not using any style, i have wrote below code in xaml, <xcdg:DataGridControl.ContextMenu>

    <ContextMenu Name="mycontextmenu">

    <MenuItem x:Name="menuItemReports" Header="Reports" />

    </ContextMenu>

    </xcdg:DataGridControl.ContextMenu>

    In Code behind file on MouseRightButtonDown event,

     private void dataGridControl1_MouseRightButtonDown(object sender, MouseEventArgs e)

    {

    if (e.RightButton == MouseButtonState.Pressed)

    IInputElement element = gridControl.InputHitTest(e.GetPosition(gridControl));

    DependencyObject parent = element as DependencyObject;

    If(parent != null)

                    {

                        Cell cell = parent as Cell;

                        if (cell != null)

                        {

     .....what happens here is cell is always null, parent object is textblock

     

     Appreciate if you help with a sample code. 

    Thanks

    Raxit

     

     

  •  07-03-2009, 12:26 PM Post no. 22256 in reply to 22239

    Re: How to limit context menu to display on non selected row in xceed wpf datagrid

    Rather than setting the ContextMenu on the grid, you can try creating an implicit style that targets DataRow and that has a Trigger based on the row's IsSelected property in which there is a Setter for the ContextMenu property.
    Senior Technical Writer
    - Xceed Software

    In three words I can sum up everything I've learned about life: it goes on.
  •  07-06-2009, 3:11 AM Post no. 22271 in reply to 22256

    Re: How to limit context menu to display on non selected row in xceed wpf datagrid

    Jenny,

     

    I tied the way you mention and it worked thanks for the response.

    One more issue, is there any way we can select single column (means column selection), way we select column in table/excel.

    I have read few post which says this feature is not available can you throw some light on same.

    If availble, which version of xceed grid has that and whats the property i can access.

     Appreciate a quick response.

    Thanks,

    Raxit

  •  07-06-2009, 8:00 AM Post no. 22280 in reply to 22271

    Re: How to limit context menu to display on non selected row in xceed wpf datagrid

    Unfortunately, this is currently a feature that is not support by Xceed DataGrid for WPF.
    Senior Technical Writer
    - Xceed Software

    In three words I can sum up everything I've learned about life: it goes on.
  •  07-06-2009, 8:13 AM Post no. 22283 in reply to 22280

    Re: How to limit context menu to display on non selected row in xceed wpf datagrid

    OK. Thanks for quick reply.

    Also by any chance can i get the current column name when user right clicks on column header.

    I am using ColumnManagerRow's PreviewMouseRightButtonDown event, the sender is ColumnManagerRow, and not sure how to get the column name/current column name using that columnManageRow.

    below is xaml which i am using

    <xcdg:DataGridControl.View>

    <xcdg:TableView UseDefaultHeadersFooters="False"

    ShowRowSelectorPane="True"

    ColumnStretchMode="All" ShowScrollTip="True">

    <xcdg:TableView.FixedHeaders>

     

    <DataTemplate>

    <xcdg:ColumnManagerRow AllowColumnReorder="False"

    AllowColumnResize="False"

    AllowAutoFilter="False"

    AllowSort="False"

    AllowDrop="False"

     

    PreviewMouseRightButtonDown="ColumnManagerRow_PreviewMouseRightButtonDown"

    />

    </DataTemplate>

    </xcdg:TableView.FixedHeaders>

    </xcdg:TableView>

    </xcdg:DataGridControl.View>

    and in code behind file..

    private void ColumnManagerRow_PreviewMouseRightButtonDown(object sender, MouseEventArgs e)

    {

    ColumnManagerRow x = sender as ColumnManagerRow;

    IInputElement element = x.InputHitTest(e.GetPosition(x));

    DependencyObject parent = element as DependencyObject;

     

     

    }

     

    Let me know your comments.

     

    Thanks

    Raxit

     

  •  07-06-2009, 9:09 AM Post no. 22285 in reply to 22283

    Re: How to limit context menu to display on non selected row in xceed wpf datagrid

    You could access the cell's ParentColumn property or check the grid's CurrentColumn property.
    Senior Technical Writer
    - Xceed Software

    In three words I can sum up everything I've learned about life: it goes on.
  •  07-06-2009, 9:43 AM Post no. 22287 in reply to 22285

    Re: How to limit context menu to display on non selected row in xceed wpf datagrid

    But sender in below code is always columnmanager not datagrid.

    private void ColumnManagerRow_PreviewMouseRightButtonDown(object sender, MouseEventArgs e)

    {

    ColumnManagerRow x = sender as ColumnManagerRow;

     so cannot get current column/cell.  Any property in ColumnManagerRow to get current column/cell

    Raxit

  •  07-06-2009, 1:45 PM Post no. 22295 in reply to 22287

    Re: How to limit context menu to display on non selected row in xceed wpf datagrid

    Use the GetParentDataGridControl method to get the parent DataGridControl and from there you can access the CurrentColumn, which may be null if nothing is selected in the grid. Maybe try handling the PreviewMouseRightButtonDown on the ColumnManagerCell type rather than ColumnManagerRow. That way, you could access the parent column through the cell's ParentColumn property. 


    Senior Technical Writer
    - Xceed Software

    In three words I can sum up everything I've learned about life: it goes on.
  •  07-07-2009, 6:39 AM Post no. 22309 in reply to 22295

    Re: How to limit context menu to display on non selected row in xceed wpf datagrid

    I was not able to find any such property on ColumnManagerRow / Cell.  Any example code will really help.

    My problem on right click on column header i have to check all checkboxes under that column.  Is there any way we can put a check box on header column? searched few post but was not able to get any clue,

     Raxit

  •  07-07-2009, 7:52 AM Post no. 22314 in reply to 22309

    Re: How to limit context menu to display on non selected row in xceed wpf datagrid

    The GetParentDataGridControl is a static method defined on the DataGridControl class. The ParentColumn property is defined on the Cell class and therefore inherited by all its derived classes. 

    This sample may help: http://xceed.com/CS/files/folders/jenny/entry14525.aspx 


    Senior Technical Writer
    - Xceed Software

    In three words I can sum up everything I've learned about life: it goes on.
  •  10-19-2009, 9:30 AM Post no. 24577 in reply to 22314

    Re: How to limit context menu to display on non selected row in xceed wpf datagrid

    Hi,

    Context menu is on by default, you can choose to show or hide columns. How would I simply disable the Context menu in XAML code?

View as RSS news feed in XML
Contact | Site Map | Reviews | Legal Terms of Use | Trademarks | Privacy Statement Copyright 2011 Xceed Software Inc.