C1Flexgrid BildContextMenu with Icon

Posted by: saidnai on 20 November 2024, 6:11 am EST

    • Post Options:
    • Link

    Posted 20 November 2024, 6:11 am EST

    Good day,

    I am using the following code to build a ContextMenu for C1Flexgrid. Is working fine. I need to add Icons. Can you please support with a sample. in VB?

    Code:

    Sub BildContextMenu()
        Try
            'Add Context menu:
            Dim menu As New ContextMenuStrip()
            Dim t As ToolStripItem = menu.Items.Add("New")
            AddHandler t.Click, AddressOf menuItem1_Click
    
            t = menu.Items.Add("Update")
            AddHandler t.Click, AddressOf menuItem2_Click
    
            t = menu.Items.Add("Delete")
            AddHandler t.Click, AddressOf menuItem3_Click
            C1FlexGrid.ContextMenuStrip = menu
    
        Catch ex As Exception
            MsgBox("Error 'BildContextMenu' : " & vbCrLf & ex.ToString, MsgBoxStyle.Critical)
        End Try
    End Sub
    
    Private Sub menuItem1_Click(sender As Object, e As EventArgs)
        Try
            MsgBox("Item 1 clicked / ID = " & GetValue(C1FlexGrid(ClickRow, 1)))
    
        Catch ex As Exception
            MsgBox("Error 'menuItem1_Click' : " & vbCrLf & ex.ToString, MsgBoxStyle.Critical)
        End Try
    End Sub
    
    Private Sub menuItem2_Click(sender As Object, e As EventArgs)
        Try
            MsgBox("Item 2 clicked / ID = " & GetValue(C1FlexGrid(ClickRow, 1)))
    
        Catch ex As Exception
            MsgBox("Error 'menuItem2_Click' : " & vbCrLf & ex.ToString, MsgBoxStyle.Critical)
        End Try
    End Sub
    
    Private Sub menuItem3_Click(sender As Object, e As EventArgs)
        Try
            MsgBox("Item 3 clicked / ID = " & GetValue(C1FlexGrid(ClickRow, 1)))
    
        Catch ex As Exception
            MsgBox("Error 'menuItem3_Click' : " & vbCrLf & ex.ToString, MsgBoxStyle.Critical)
        End Try
    End Sub
    

    Thanks

    Said

  • Posted 20 November 2024, 8:22 am EST

    Hello Said,

    You can use the Image property of the ToolStripItem to set the icon of the command in the context menu. Please refer to the attached sample for implementation. (See FlexGrid_ContextMenu_VB.zip)

    Regards,

    Uttkarsh.

  • Posted 20 November 2024, 11:32 am EST - Updated 20 November 2024, 11:37 am EST

    Dear Uttkarsh,

    The sample is working fine as i need. As i implemented the following line :

    “*t.Image = Image.FromStream(New MemoryStream(My.Resources.NewImg))*****”

    I got error. So the icons(.bmp) on my side they are in an ImageList1 and not under Resources.

    So is it possible to use ImageList1 in this case?

    Best regards

    Said

  • Posted 21 November 2024, 1:24 am EST

    Hello Said,

    Please refer to the modified sample for implementation. (see FlexGrid_ContextMenu_VB_Mod.zip)

    We’ve now used ImageList to get the images.

    Regards,

    Uttkarsh.

  • Posted 21 November 2024, 3:26 am EST

    Dear Uttkarsh,

    Perfect.

    Best regards

    Said

Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels