We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

Adding different ContextMenu each GridDataVisibleColumn in XAML

I have a datagrid with ten columns and would like to add a contextmenu specific to each column in XAML, is this possible?  I see that the GridDataVisible.ColumnStyle has a ContextMenuItems property, but was not able to figure out how to use it.

4 Replies

ED Ed replied to Ed April 4, 2014 08:53 PM UTC

I have a datagrid with ten columns and would like to add a contextmenu specific to each column in XAML, is this possible?  I see that the GridDataVisible.ColumnStyle has a ContextMenuItems property, but was not able to figure out how to use it.

This is the XAML for one of the columns i was trying to set a context menu for:
 
 <syncfusion:GridDataVisibleColumn MappingName="Att.Location" AllowFilter="False" AllowDrag="False" HeaderText="Location" DataType="String">                      
                    <syncfusion:GridDataVisibleColumn.ColumnStyle>
                        <syncfusion:GridDataColumnStyle HorizontalAlignment="Left" ReadOnly="True" CellTypeEnum="TextBox">
                            <syncfusion:GridStyleInfo.ContextMenuItems>
                                 <MenuItems:RecordMenuItems>
                                    <MenuItem
                                        Header="Get Location Details"
                                        Command="DataGrid:GridCommands.GetDetails"     
                                        CommandTarget="{Binding Path=PlacementTarget,
                                            RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type ContextMenu}}}"
                                        CommandParameter="{Binding GridSelectedItem}">
                                    </MenuItem>
                                </MenuItems:RecordMenuItems>
                            </syncfusion:GridStyleInfo.ContextMenuItems>
                        </syncfusion:GridDataColumnStyle>
                    </syncfusion:GridDataVisibleColumn.ColumnStyle>
                    <syncfusion:GridDataVisibleColumn.HeaderStyle>
                        <syncfusion:GridDataColumnStyle HorizontalAlignment="Center"/>
                    </syncfusion:GridDataVisibleColumn.HeaderStyle>
                </syncfusion:GridDataVisibleColumn>


PR Pradeepa R V Syncfusion Team April 9, 2014 02:23 PM UTC

Hi Ed

 

You can specify ContextMenu for specific columns by handling QueryContextMenuInfo event. .Please find the code snippet below,

 

Code Snippet:

 

List<MenuItem> menuitems = new List<MenuItem>();

        public MainWindow()

        {

            InitializeComponent();

            menuitems.Add(new MenuItem() { Header = "Item 1" });

            menuitems.Add(new MenuItem() { Header = "Item 2" });

 

            this.dataGrid1.Model.QueryContextMenuInfo += Model_QueryContextMenuInfo;

        }

 

        void Model_QueryContextMenuInfo(object sender, GridQueryContextMenuInfoEventArgs e)

        {

            var style = e.Style as GridDataStyleInfo;

            if ( style.CellIdentity.Column!=null && style.CellIdentity.Column.MappingName == "SupplierID")

            {

 

                e.Style.ContextMenuItems = menuitems;

            }

        }

 

We created a simple sample regarding this.Please find the attached sample below.

 

 

Please let us know if you have any concern.

 

Regards

Pradeepa


Attachment: Cotextmenu_for_one_column_c19fdaff.zip


ED Ed April 9, 2014 08:17 PM UTC

Perfect thanks for your help.


PR Pradeepa R V Syncfusion Team April 16, 2014 03:36 AM UTC

Hi Ed

 

Thanks for your update.

 

Please let us know if you require further assistance.

 

Regards

Pradeepa


Loader.
Live Chat Icon For mobile
Up arrow icon