Hi, my intention is to display a RadcontextMenu on a RadListControl when a mouse right-button is pressed or released (depending on the ClickMode configuration of the RadListControl).
I just would like to threat a right-button click in the same way as a left-button click is threated by default in a RadListControl, but I don't know whether Telerik provides a way to do this just by setting an specific property or somethins similar, what I'm doing is iterating the RadListControl items and determine which item contains the current mouse location but maybe this is a heavy method for big list item collections.
Pleasse. could you check my approach to see if it can be improved/simplified in some way via Telerik?
Also, I have an unsolved problem, in the line 96 of the code below I would like to determine which radListControl called the RadContextMenu to retrieve its SelectedItem.Text property, but I don't know if its possibly.
Thanks in advance.
I just would like to threat a right-button click in the same way as a left-button click is threated by default in a RadListControl, but I don't know whether Telerik provides a way to do this just by setting an specific property or somethins similar, what I'm doing is iterating the RadListControl items and determine which item contains the current mouse location but maybe this is a heavy method for big list item collections.
Pleasse. could you check my approach to see if it can be improved/simplified in some way via Telerik?
Also, I have an unsolved problem, in the line 96 of the code below I would like to determine which radListControl called the RadContextMenu to retrieve its SelectedItem.Text property, but I don't know if its possibly.
Thanks in advance.
001.Option Strict On002.Option Explicit On003.Option Infer Off004. 005.Imports Telerik.WinControls006.Imports Telerik.WinControls.Enumerations007.Imports Telerik.WinControls.UI008. 009.Public Class RadContextMenu_TestForm010. 011. Private Shadows Sub Load() Handles MyBase.Load012. 013. ' Set the RadListControl behavior014. With Me.RadListControl1015. .SortStyle = SortStyle.Ascending016. .SelectionMode = SelectionMode.One017. .ListElement.ClickMode = ClickMode.Release018. End With019. 020. ' Set the listRadListControl items021. Me.RadListControl1.DataSource =022. From p As Process In Process.GetProcesses023. Select p.ProcessName024. 025. End Sub026. 027. ''' <summary>028. ''' Shows a RAD context menu on the active <see cref="RadListControl"/> item.029. ''' </summary>030. ''' <param name="ctrl">The <see cref="RadListControl"/> control.</param>031. ''' <param name="ctxm">The <see cref="RadContextMenu"/> to show.</param>032. Private Sub ShowRadContextMenu(ByVal ctrl As RadListControl,033. ByVal ctxm As RadContextMenu)034. 035. For Each Item As RadListDataItem In ctrl.Items036. 037. If Item.VisualItem IsNot Nothing AndAlso Item.VisualItem.IsMouseOverElement Then038. Item.Selected = True039. ctxm.Show(MousePosition)040. End If041. 042. Next Item043. 044. End Sub045. 046. ''' <summary>047. ''' Handles the MouseDown event of the RadListControl1 control.048. ''' </summary>049. ''' <param name="sender">The source of the event.</param>050. ''' <param name="e">The <see cref="MouseEventArgs"/> instance containing the event data.</param>051. Private Sub RadListControl1_MouseDown(ByVal sender As Object, ByVal e As MouseEventArgs) _052. Handles RadListControl1.MouseDown053. 054. Dim ctrl As RadListControl = DirectCast(sender, RadListControl)055. 056. If (e.Button = Windows.Forms.MouseButtons.Right) _057. AndAlso (ctrl.ListElement.ClickMode = ClickMode.Press) Then058. 059. Me.ShowRadContextMenu(ctrl, Me.RadContextMenu1)060. 061. End If062. 063. End Sub064. 065. ''' <summary>066. ''' Handles the MouseUp event of the RadListControl1 control.067. ''' </summary>068. ''' <param name="sender">The source of the event.</param>069. ''' <param name="e">The <see cref="MouseEventArgs"/> instance containing the event data.</param>070. Private Sub RadListControl1_MouseUp(ByVal sender As Object, ByVal e As MouseEventArgs) _071. Handles RadListControl1.MouseUp072. 073. Dim ctrl As RadListControl = DirectCast(sender, RadListControl)074. 075. If (e.Button = Windows.Forms.MouseButtons.Right) _076. AndAlso (ctrl.ListElement.ClickMode = ClickMode.Release _077. OrElse078. ctrl.ListElement.ClickMode = ClickMode.Hover) Then079. 080. Me.ShowRadContextMenu(ctrl, Me.RadContextMenu1)081. 082. End If083. 084. End Sub085. 086. ''' <summary>087. ''' Handles the Click event of the RadMenuItem1 control.088. ''' </summary>089. ''' <param name="sender">The source of the event.</param>090. ''' <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>091. Private Sub RadMenuItem1_AddToExclusionList_Click(ByVal sender As Object, ByVal e As EventArgs) _092. Handles RadMenuItem1.Click093. 094. If DirectCast(e, MouseEventArgs).Button = Windows.Forms.MouseButtons.Left Then095. 096. MessageBox.Show(DirectCast(RadMenuItem1.OwnerControl, RadListControl).SelectedItem.Text)097. 098. End If099. 100. End Sub101. 102.End Class