I was unable to make this code working:
Function MouseDown(x As Integer, y As Integer) Handles MouseDown As Boolean
If IsContextualClick Then
Var row As Integer = Me.RowFromXY(x, y)
Var column As Integer = Me.ColumnFromXY(x, y)
// Check if the click is in the header area (RowFromXY typically returns -1 for the header)
If row = -1 And column >= 0 Then
// *** Contextual Click on a Column Header ***
Var headerMenu As New DesktopMenuItem
headerMenu.AddMenu(New DesktopMenuItem("Sort by " + Me.HeaderAt(column)))
headerMenu.AddMenu(New DesktopMenuItem("Hide Column " + column.ToString))
// Display the custom menu
Var selectedItem As DesktopMenuItem = headerMenu.PopUp
If selectedItem <> Nil Then
Select Case selectedItem.Text
Case "Sort by " + Me.HeaderAt(column)
// Place code to handle sorting here
Case "Hide Column " + column.ToString
// Place code to handle column hiding here
End Select
End If
// I handled the Click
Return True
End If
End If
// Let the framework deal with the click
Return False // Click in he ListBox core
End Function
Then, I add a Canvas above the ListBox header, paste that code in MouseDown.
I had to comment all instructions for the DesktopListBox.
Now: Row = x , Columns = y
Commented the Menu names to remove DLB code.
Once the code compiled, a Right-Click in the DesktopListBox’s Header shows the two Contextual items created:
Of course, the Menus do nothing, but the first step was to create them.
Must I stay with that solution or do you see something to change to make it work directly in the DesktopListBox
