Hi SF,
I have 3 controls (will be hundreds eventually) for which I want to have a common right click menu.
I have assigned a CSS class to the 3 controls ('audited') as follows:
<SfTextBox ID="@nameof(BusinessUnitModel.Name)" CssClass="audited" ... />
and set the context menu target as follows:
<SfContextMenu Target=".audited" ...>
This works and the right click menu is displayed on all 3 controls, however after selecting an item from the menu, the 'Element' property is contains NULL and no indication of the SfTextBox which was right clicked.
How do I determine which control was right-clicked on?
Thanks
Hi JB,
We have checked your reported query, and in the ItemSelected event, we have sent only the context menu ID, not the target element ID. We have prepared the sample based on your requirements. Binding the mouse-down event to the textbox, we can get the context menu opened textbox element id shown below.
<SfTextBox CssClass="audited" @onmousedown='@(e => OnRightClick(e, i))'></SfTextBox> …………………… private void selectedHandler(MenuEventArgs<MenuItem> args) { var SelectedItem = args.Item; var textBox = SelectedTextBox; } private void OnRightClick(MouseEventArgs e, string ID) { if (e.Button == 2) { SelectedTextBox = ID; } } |
Please refer to the attached sample code and get back to us if you need any further assistance on this.
Regards,
YuvanShankar A
Thanks - not an ideal approach since I will have to add that onmousedown to every control, but it will suffice.
Sorry for the delay, JB.
Confirmed this as an issue and logged a bug report. The fix will be available in our upcoming patch release planned for 15th February 2023.
Feedback link for tracking purpose: https://www.syncfusion.com/feedback/40807/provide-the-target-elements-id-as-parameter-to-opened-onopen-event-of-context-menu
You will be informed regarding this once the fix is published.
Disclaimer: “Inclusion of this solution in the weekly release may change due to other factors including but not limited to QA checks and works reprioritization.”
JB,
We are glad to announce our weekly patch release (20.4.0.50) is rolled out. We have included the fix for this “Provide the target element's id as parameter to Opened & OnOpen event of context menu” issue in this release. So, we suggest you upgrade our Syncfusion packages to our latest version to resolve this issue in your end. (20.4.0.50).
Feedback link: https://www.syncfusion.com/feedback/40807/provide-the-target-elements-id-as-parameter-to-opened-onopen-event-of-context-menu
Please refer to the below code snippet for getting the target Id.
<SfContextMenu Target=".audited" TValue="MenuItem"> <MenuItems> <MenuItem Text="Cut"></MenuItem> <MenuItem Text="Copy"></MenuItem> <MenuItem Text="Paste"></MenuItem> </MenuItems> <MenuEvents TValue="MenuItem" OnOpen="@onOpenHandler" ItemSelected="@selectedHandler"></MenuEvents> </SfContextMenu> ……… private void onOpenHandler(BeforeOpenCloseMenuEventArgs<MenuItem> e) { SelectedTextBox = e.TargetId; } |