This is a migrated thread and some comments may be shown as answers.

RadMenuItem in RadGridView Events

1 Answer 90 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Mike
Top achievements
Rank 2
Mike asked on 07 Mar 2008, 07:52 PM
I have a radgridviw. In the last column of the gridview, I would like to use a menu items to provide additional functionality such as viewing documents, editing documents, etc. I have the controls loaded in the grid, and they display fine, but I can not capture any events in the column containing the menu items. Code pasted below.

public partial class LALA: UserControl
    {
        public LALA()
        {
            InitializeComponent();
            BindToDataReader();
            gvManageDocs.CellFormatting += new  CellFormattingEventHandler(gvManageDocs_CellFormatting);             
        }
     

        private void gvManageDocs_CellFormatting(object sender, CellFormattingEventArgs e) 
            {

                if (e.CellElement is GridCommandCellElement) 
                { 
                    if (e.CellElement.Children[0] is RadButtonElement ) 
                    { 
                        e.CellElement.Children.Clear();

                        RadMenuElement buttonElement = new RadMenuElement(); 
                        //RadDropDownButtonElement buttonElement = new RadDropDownButtonElement();
                        buttonElement.Items.Add(new RadMenuItem("view")); 
                        buttonElement.Items.Add(new RadMenuItem("modify")); 
                        buttonElement.Items.Add(new RadMenuItem("release"));
                        buttonElement.Items.Add(new RadMenuItem("new")); 
                        e.CellElement.Children.Add(buttonElement); 

                    } 
                } 
            } 

        private void BindToDataReader()
        {

            gvManageDocs.GridElement.BeginUpdate();
            gvManageDocs.MasterGridViewTemplate.Columns.Clear();
            gvManageDocs.GridElement.EndUpdate(false);
            gvManageDocs.GridElement.BeginUpdate();

            gvManageDocs.MasterGridViewTemplate.AutoGenerateColumns = false;
            gvManageDocs.MasterGridViewTemplate.AllowAutoSizeColumns = true;
            gvManageDocs.MasterGridViewTemplate.AllowAddNewRow = false;

            char[] delimiterChars = { ',' };
            string strHeaders = AppGlobal.g_strAllManageHeaders;
            string[] allHeaders = strHeaders.Split(delimiterChars);
            string strDataFields = AppGlobal.g_strAllManageData;
            string[] allDataFields = strDataFields.Split(delimiterChars);

            for (int x = 0; x < allHeaders.Length; x++)
            {               
                if (x == allHeaders.Length-1)
                {
                    GridViewCommandColumn column = new GridViewCommandColumn();
                    column.HeaderText = allHeaders[x].ToString();
                    column.DataField = allDataFields[x].ToString();
                    gvManageDocs.MasterGridViewTemplate.Columns.Add(column);
                    column = null;
                }
                else
                {
                    GridViewTextBoxColumn column = new GridViewTextBoxColumn();
                    column.HeaderText = allHeaders[x].ToString();
                    column.DataField = allDataFields[x].ToString();
                    gvManageDocs.MasterGridViewTemplate.Columns.Add(column);
                    column = null;
                }
            }
        
 
             gvManageDocs.GridElement.EndUpdate(false);
           
            this.gvManageDocs.DataSource = DATASET
           
           
        }

    }

1 Answer, 1 is accepted

Sort by
0
Accepted
Jack
Telerik team
answered on 10 Mar 2008, 01:39 PM
Hi mike scardina,

Thank you for contacting us.

In order to capture events from menu items, you should process the Click event of the RadMenuItem. Refer to the code snippet below:

RadMenuItem item = new RadMenuItem("view"); 
item.Click += new EventHandler(item_Click); 
buttonElement.Items.Add(item); 
 
        void item_Click(object sender, EventArgs e) 
    MessageBox.Show("View menu item clicked!");             
 

I hope this helps. Do not hesitate to write me, if you have other questions.

Greetings,
Jack
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
Tags
GridView
Asked by
Mike
Top achievements
Rank 2
Answers by
Jack
Telerik team
Share this question
or