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

Context menu left empty header cell

2 Answers 184 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Gerald
Top achievements
Rank 1
Gerald asked on 21 Sep 2010, 03:19 PM
Dear Telerik-guys,

Using your GridView I'd like to create the following:

In the grid there is an empty 'cell' in the header (on the left, see Grid1.png), here I'd like to create a context menu for some general gridfunctions (like Grid2.png).

Could you give me some pointers on how to accomplish this?

Thanks in advance!

2 Answers, 1 is accepted

Sort by
0
Jack
Telerik team
answered on 24 Sep 2010, 04:07 PM
Hi Gerald,

Thank you for this question. The specified cell is an element of type GridTableHeaderCellElement and you can draw an image inside it when you enable the custom drawing and handle the CellPaint event. Here is a sample:
this.radGridView1.EnableCustomDrawing = true;
void radGridView1_CellPaint(object sender, GridViewCellPaintEventArgs e)
{
    if (e.Cell is GridTableHeaderCellElement)
    {
        e.Graphics.DrawImage(Resources.arrow, 2, 2);
    }
}

To add a context menu, handle the MouseDown event of RadGridView:
void radGridView1_MouseDown(object sender, MouseEventArgs e)
{
    if (e.Button == System.Windows.Forms.MouseButtons.Right)
    {
        GridTableHeaderCellElement cell = this.radGridView1.ElementTree.GetElementAtPoint(e.Location) as GridTableHeaderCellElement;
        if (cell != null)
        {
            RadDropDownMenu menu = new RadDropDownMenu();
            menu.Items.Add(new RadMenuItem("Item 1"));
            menu.Items.Add(new RadMenuItem("Item 2"));
            menu.Items.Add(new RadMenuItem("Item 3"));
            menu.Show(this.radGridView1, e.Location);
        }
    }
}

I hope this helps.

 

Regards,
Jack
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Gerald
Top achievements
Rank 1
answered on 27 Sep 2010, 08:49 AM

Hi Jack,

Just what I needed!
Thank you!

Tags
GridView
Asked by
Gerald
Top achievements
Rank 1
Answers by
Jack
Telerik team
Gerald
Top achievements
Rank 1
Share this question
or