Satyaprakash
Top achievements
Rank 1
Satyaprakash
asked on 30 Jun 2008, 03:19 PM
Hi,
I have applied group by expression on Country and City column of a Table which contain information of comapnies using a windows form RadgridView control.
Now I want to show a context menu when the user right click on the row which contain the (GridGroupExpanderCellElement and GridRowHeaderCellElement)
i.e (+ Country :England and City:London).
Is the above functionality possible ?
If yes please expalin it with an example.
I have applied group by expression on Country and City column of a Table which contain information of comapnies using a windows form RadgridView control.
Now I want to show a context menu when the user right click on the row which contain the (GridGroupExpanderCellElement and GridRowHeaderCellElement)
i.e (+ Country :England and City:London).
Is the above functionality possible ?
If yes please expalin it with an example.
3 Answers, 1 is accepted
0
Hi Satyaprakash,
Thank you for this question.
Up to the question: Yes, implementing this functionality with RadGridView is possible.
Generally, you should process the ContextMenuOpening event and set a context menu. This message is fired every time when RadGridView shows a context menu. However, group rows in grid doesn't show a context menu. Because of this you should process the MouseDown event and get the element hovered by the mouse using the GetElementAtPoint method.
Consider the following code snippet:
Please let me know if you need further assistance.
Regards,
Jack
the Telerik team
Instantly find answers to your questions at the new Telerik Support Center
Thank you for this question.
Up to the question: Yes, implementing this functionality with RadGridView is possible.
Generally, you should process the ContextMenuOpening event and set a context menu. This message is fired every time when RadGridView shows a context menu. However, group rows in grid doesn't show a context menu. Because of this you should process the MouseDown event and get the element hovered by the mouse using the GetElementAtPoint method.
Consider the following code snippet:
void radGridView1_MouseDown(object sender, MouseEventArgs e) |
{ |
if (e.Button == MouseButtons.Right) |
{ |
RadGridView grid = (RadGridView)sender; |
GridCellElement cell = grid.ElementTree.GetElementAtPoint(e.Location) as GridCellElement; |
if (cell != null && cell.RowInfo is GridViewGroupRowInfo) |
{ |
if ((string)cell.RowInfo.Cells["Country"].Value == "England" && |
(string)cell.RowInfo.Cells["City"].Value == "London") |
{ |
RadDropDownMenu menu = new RadDropDownMenu(); |
RadMenuItem item = new RadMenuItem("Item 1"); |
item.Click += new EventHandler(item_Click); |
menu.Items.Add(item); |
item = new RadMenuItem("Item 2"); |
item.Click += new EventHandler(item_Click); |
menu.Items.Add(item); |
menu.Show(Control.MousePosition); |
} |
} |
} |
} |
Please let me know if you need further assistance.
Regards,
Jack
the Telerik team
Instantly find answers to your questions at the new Telerik Support Center
0
Satyaprakash
Top achievements
Rank 1
answered on 01 Jul 2008, 03:06 PM
Hi Jack,
Thanks for your reply.
The reply u send did provide me help. but it could not meet my requirement.
Basically i want to show contenxt menu on any GridViewGroupRowInfo elemnt.i.e(when user click on Country: England) not on the GridGroupExpanderCellElement.
The code you send make it hard coded.so when the user click on that specific elemnt it will show contetx menu. I dont want that way.
Also the radGridView1_MouseDown event get called when the user right click on (+ sign i.e GridGroupExpanderCellElement).
But I want to call radGridView1_MouseDown when the user right click on (Country: England , Country: USA).
Hoping to get a reply soon.
Thanks for your reply.
The reply u send did provide me help. but it could not meet my requirement.
Basically i want to show contenxt menu on any GridViewGroupRowInfo elemnt.i.e(when user click on Country: England) not on the GridGroupExpanderCellElement.
The code you send make it hard coded.so when the user click on that specific elemnt it will show contetx menu. I dont want that way.
Also the radGridView1_MouseDown event get called when the user right click on (+ sign i.e GridGroupExpanderCellElement).
But I want to call radGridView1_MouseDown when the user right click on (Country: England , Country: USA).
Hoping to get a reply soon.
0
Hi Satyaprakash,
Thank you for getting back to me.
You can exclude the GridGroupExpanderCellElement using an if statement. Check out the code below:
I hope this helps. Should you have other questions, please let me know.
Sincerely yours,
Jack
the Telerik team
Instantly find answers to your questions at the new Telerik Support Center
Thank you for getting back to me.
You can exclude the GridGroupExpanderCellElement using an if statement. Check out the code below:
void radGridView1_MouseDown(object sender, MouseEventArgs e) |
{ |
if (e.Button == MouseButtons.Right) |
{ |
RadGridView grid = (RadGridView)sender; |
GridCellElement cell = grid.ElementTree.GetElementAtPoint(e.Location) as GridCellElement; |
if (cell != null && cell.RowInfo is GridViewGroupRowInfo && |
!(cell is GridGroupExpanderCellElement) && |
!(cell is GridRowHeaderCellElement)) |
{ |
RadDropDownMenu menu = new RadDropDownMenu(); |
RadMenuItem item = new RadMenuItem("Item 1"); |
item.Click += new EventHandler(item_Click); |
menu.Items.Add(item); |
item = new RadMenuItem("Item 2"); |
item.Click += new EventHandler(item_Click); |
menu.Items.Add(item); |
menu.Show(Control.MousePosition); |
} |
} |
} |
I hope this helps. Should you have other questions, please let me know.
Sincerely yours,
Jack
the Telerik team
Instantly find answers to your questions at the new Telerik Support Center