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

Gridview customised context menu

1 Answer 95 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Sree
Top achievements
Rank 1
Sree asked on 06 Mar 2013, 03:55 AM
Hello Team
I have a requirement in gridview where user inserts columns to the grid and also removes when ever he wants, when he removes the column i need to delete the column from database, see the below image



when user clicks the contextmenu Remove Field i need to delete the column from the database table

for this i have written  MenuItemRemove.Click += new EventHandler(MenuItemRemove_Click);

void MenuItemRemove_Click(object sender, EventArgs e)
{
  string iColName = radgridview1.CurrentColumn.Name;
// delete query to delete the above column from the database
}

my problem here is i selected fifth column in the grid, and the current column is always returning column index as 0 which means column one, how to capture the selected column index or name when clicked the context menu remove in my example

please help me


1 Answer, 1 is accepted

Sort by
0
Accepted
Stefan
Telerik team
answered on 08 Mar 2013, 02:44 PM
Hi Lakshmi,

Thank you for writing.

You can save the column in the menu item Tag, and then get a reference to it in the Click event handler. Here is an example:
void radGridView1_ContextMenuOpening(object sender, ContextMenuOpeningEventArgs e)
{
    RadMenuItem MenuItemRemove = new RadMenuItem("Remove column");
    e.ContextMenu.Items.Add(MenuItemRemove);
    MenuItemRemove.Tag = e.ContextMenuProvider;
    MenuItemRemove.Click += new EventHandler(MenuItemRemove_Click);
}
 
void MenuItemRemove_Click(object sender, EventArgs e)
{
    RadMenuItem clickedItem = (RadMenuItem)sender;
    GridCellElement cellElement = (GridCellElement)clickedItem.Tag;
    GridViewColumn column = cellElement.ColumnInfo;
    string iColName = column.Name;
    RadMessageBox.Show(iColName);
    // delete query to delete the above column from the database
}

I hope this helps.
 

Kind regards,
Stefan
the Telerik team
WinForms Q1 2013 boasts PivotGrid, PDF Viewer, Chart enhancements and more. Check out all of the latest highlights.
Tags
GridView
Asked by
Sree
Top achievements
Rank 1
Answers by
Stefan
Telerik team
Share this question
or