Fog Creek Software
Discussion Board

Welcome! and rules

Joel on Software

Upgrading Flexgrid pt II (Suma)

An email request from someone called "suma" asked whether I had managed to do this. The return mail address is invalid, so I'll post the replies here. They're not personal and may prove useful to other people anyway.

I am facing the same problem while assigning the context menu to Flexgrid.
Did you get any suggetions from the group?. Could you help me ?

Replies 1----------------------------
There were absolutely no suggestions made by the group.

I eventually reached the conclusion that you're better off either

a) rewriting your code to use a data grid
b) upgrading to the .Net version of Flexgrid (available from ComponentOne. Use google) at a cost
c) identifying the problems with Flexgrid and coding around them

I went with c) as they were only small apps and we were only really trying to get a feel for how many problems we were likely to get doing a "for real" conversion on the main apps.

b) was a non starter as there's no free download to evaluate - they may have changed this policy though. hav a look.

The context menu was difficult to solve, but once solved quite easy to code. I'll mail you a description of what I did tomorrow, as it's on my work pc.

I found that by far the biggest difficulty was the sloppy coding that was being upgraded. People's reliance on default properties and the slight difference between the .Net versions mean you end up trawling through loads of warnings and errors.

The best advice I can give is tidy up your existing code in VB6 before upgrading, preferably using an automated tool. No such tool exists; you'll have to write one, but it's not too hard. In VB6, write a tool which opens a vbp and parses it for project files. Create an array or similar, then open and parse (a copy of) each file in turn. Create a search/replace code template and save out to the original file (not the copy you're reading from).

Hope that's understandable. It's now 19:00 and I've been awake since 03:30.



Replies 2----------------------------

In the upgraded project (in .Net studio)....


1) Menu object
Make sure the form has a context menu on it


NB Not a MenuItem or Menu (I think one of these is the upgrade default).

Use Edit Menu to add menu items to it. NB You'll need events to trap these
being clicked


2) Associate context menu

In InitializeComponent(), make sure you assign the context menu to the

        Me.MSFlexGrid1.ContextMenu = Me.mnuContextMenu


3) Display context menu

Drop the following function call into the click event. NB may want to also
check it's the RH mouse button.

Private Sub MSFlexGrid1_ClickEvent(ByVal eventSender As System.Object, ByVal
eventArgs As System.EventArgs) Handles MSFlexGrid1.ClickEvent

PopupMenu(Me.mnuContextMenu, Me.MSFlexGrid1)

End Sub

In a public module (e.g. MenuLibrary.vb), Add the following

    Public Sub PopupMenu(ByRef PopupMenu As
System.Windows.Forms.ContextMenu, _
                        ByRef MSFlexGrid As AxMSFlexGridLib.AxMSFlexGrid)

        Const FG_ROW_HEIGHT = 20            ' Height of the FlexGridRow
        Const FG_CELL_OFFSET = 20          ' Amount offset from L/H edge of

        Dim ContextMenuPos As System.Drawing.Point
        Dim FlexgridPos As System.Drawing.Point
        Dim FlexgridPosX As Integer
        Dim FlexgridPosY As Integer

        ' Get the x/y screen position for the FlexGrid
        FlexgridPosX = MSFlexGrid.Location.X
        FlexgridPosY = MSFlexGrid.Location.Y

        ' Add offsets to both x/y coords to get the correct screen position
for the ContextMenu
        FlexgridPosY = FlexgridPosY + (MSFlexGrid.Row * FG_ROW_HEIGHT)
        FlexgridPosX = FlexgridPosX + (FG_CELL_OFFSET)

        ContextMenuPos.X = FlexgridPosX
        ContextMenuPos.Y = FlexgridPosY

        PopupMenu.Show(MSFlexGrid, ContextMenuPos)

    End Sub

Friday, May 21, 2004

*  Recent Topics

*  Fog Creek Home