Hi all,
I like to get the top level control of a RadMenuItem.
For example: there is a RadForm with two RadGridView controls.
Each containing a ContextMenu. For both I'm using the same handler which should recognize on which RadGridView the menu is clicked.
How can I retrieve the RadGridView which is the top level for the ContextMenu?
Regards
Hardy
I like to get the top level control of a RadMenuItem.
For example: there is a RadForm with two RadGridView controls.
Each containing a ContextMenu. For both I'm using the same handler which should recognize on which RadGridView the menu is clicked.
How can I retrieve the RadGridView which is the top level for the ContextMenu?
Regards
Hardy
4 Answers, 1 is accepted
0
Hello Hardy,
Thank you for writing.
You can save the grid instance in the Tag property of the menu and later retrieve it in the click event handler. Here is a small sample:
I hope that you find this information useful.
Kind regards,
Stefan
the Telerik team
Thank you for writing.
You can save the grid instance in the Tag property of the menu and later retrieve it in the click event handler. Here is a small sample:
public
partial
class
Form1 : Form
{
public
Form1()
{
InitializeComponent();
Random r =
new
Random();
DataTable table =
new
DataTable();
table.Columns.Add(
"ID"
,
typeof
(
int
));
table.Columns.Add(
"Name"
,
typeof
(
string
));
table.Columns.Add(
"Bool"
,
typeof
(
bool
));
table.Columns.Add(
"DateColumn"
,
typeof
(DateTime));
for
(
int
i = 0; i < 10; i++)
{
table.Rows.Add(i,
"Row "
+ i, r.Next(10) > 5 ?
true
:
false
, DateTime.Now.AddHours(i));
}
this
.radGridView1.DataSource = table;
this
.radGridView2.DataSource = table;
RadMenuItem item =
new
RadMenuItem(
"item"
);
item.Click += item_Click;
menu.Items.Add(item);
radGridView1.ContextMenuOpening += radGridView1_ContextMenuOpening;
radGridView2.ContextMenuOpening += radGridView1_ContextMenuOpening;
}
RadContextMenu menu =
new
RadContextMenu();
void
radGridView1_ContextMenuOpening(
object
sender, ContextMenuOpeningEventArgs e)
{
e.ContextMenu = menu.DropDown;
menu.DropDown.Tag = sender;
}
void
item_Click(
object
sender, EventArgs e)
{
RadMenuItem item = (RadMenuItem)sender;
RadGridView grid = (RadGridView)item.OwnerControl.Tag;
}
I hope that you find this information useful.
Kind regards,
Stefan
the Telerik team
WinForms Q1 2013 boasts PivotGrid, PDF Viewer, Chart enhancements and more.
Check out all of the latest highlights.
0
Hardy
Top achievements
Rank 1
answered on 14 Mar 2013, 05:23 PM
Hi Stefan,
it's a possible workaround.
I would like to get a property like menu.parent or menu.toplevelcontrol...
Using the tag property is ok but in my solution I'm using the tag for other information.
I solved the problem using a lookup table where any menu is stored with its grid
Now I can select the menu's parent from the table.
Regards
Hardy
it's a possible workaround.
I would like to get a property like menu.parent or menu.toplevelcontrol...
Using the tag property is ok but in my solution I'm using the tag for other information.
I solved the problem using a lookup table where any menu is stored with its grid
Now I can select the menu's parent from the table.
Regards
Hardy
0
Hello Hardy,
I am glad that you have found a suitable solution for your case.
The parent of the menu items will be the element from the popup element tree, and since this popup is not part of the control, you cannot find the control in the element tree.
Since you mention that the tag of the context menu was already taken, you can create a custom object that will hold both your object and the parent or you can use the Tag of the menu item.
I hope that you find this information useful.
All the best,
Stefan
the Telerik team
I am glad that you have found a suitable solution for your case.
The parent of the menu items will be the element from the popup element tree, and since this popup is not part of the control, you cannot find the control in the element tree.
Since you mention that the tag of the context menu was already taken, you can create a custom object that will hold both your object and the parent or you can use the Tag of the menu item.
I hope that you find this information useful.
All the best,
Stefan
the Telerik team
WinForms Q1 2013 boasts PivotGrid, PDF Viewer, Chart enhancements and more.
Check out all of the latest highlights.
0
Scott
Top achievements
Rank 1
answered on 24 Apr 2020, 03:28 PM
Worked great! Thank you.
-Scott