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. (Last updated on : Nov 16th 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Adding different ContextMenu each GridDataVisibleColumn in XAML

Thread ID:

Created:

Updated:

Platform:

Replies:

116119 Apr 4,2014 08:39 PM UTC Apr 16,2014 03:36 AM UTC WPF 4
loading
Tags: GridDataControl
Ed
Asked On April 4, 2014 08:39 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.

Ed
Replied On 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>

Pradeepa R V [Syncfusion]
Replied On 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
Replied On April 9, 2014 08:17 PM UTC

Perfect thanks for your help.

Pradeepa R V [Syncfusion]
Replied On April 16, 2014 03:36 AM UTC

Hi Ed

 

Thanks for your update.

 

Please let us know if you require further assistance.

 

Regards

Pradeepa


CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

;