How can I set column width in MSFlexGrid (Studio 2010)

Locked How can I set column width in MSFlexGrid (Studio 2010)

  • Thursday, March 15, 2012 6:45 PM
     
     

    I'm at the Studio 2008 stage in migrating from VB6 to Studio 2010. My application appears to run OK for the most part, but my MSFlexGrid display's single column is just 8 or 10 characters wide -- it should span the entire grid display (i.e., have the same width as the grid).

    The Studio 2008-Upgraded code sets several grid properties correctly, but the statement ".ColWidth(0) = .Width" (in the scope of a With block) causes an error. So does the statement ".TextMatrix(0, 0) = string".

    Not only are these properties not included in the upgraded control (now identified as AxMSFlexGrid), but some column-related properties are greyed out in the properties list. My grid size was set originally by cursor drag, and the present .Size sub-properties of .Width and .Height are set to the numbers 593 and 329, respectively. (My form has a fixed size and is user-moveable but not user resizable.)

    Price Buhrman

All Replies

  • Thursday, March 15, 2012 9:22 PM
     
      Has Code

    When I answered last time, I wasn't aware I have a VM with VB 6 including the MSFlexGrid installed... Now I am. :)

    So I let'em upgrade the line

    MSFlexGrid1.ColWidth(1) = 1440

    and the result is

    MSFlexGrid1.set_ColWidth(1, 1440)

    And it works.

    So there are two questions for your project:
    - Why hasn't it been upgrade to set_ColWidth? Maybe late-binding is used, i.e. the variable is not of type MSFlexGrid?
    - Why doesn't the compiler find set_ColWidth now if you change it manually? I can't tell because it works here.


    Armin

  • Friday, March 16, 2012 6:34 PM
     
     

    Some progress.

    My upgraded control is AxMSFlexGridLib.AxMSFlexGrid. Using the Object Browser, I found the proposed property "setting" under MSFlexGridLib, and its name is MSFlexGridLib.MSFlexGrid.IMSFlexGrid. I inserted your suggested statement into my code (within a With/End With block) and got, not a simple compilation error, but an unhandeled COMException error. The details are as follows:

    System.Runtime.InteropServices.COMException was unhandled
      ErrorCode=-2146798278
      Message="Exception from HRESULT: 0x800A753A"
      Source="Interop.MSFlexGridLib"
      StackTrace:
           at MSFlexGridLib.IMSFlexGrid.set_ColWidth(Int32 index, Int32 ColWidth)
           at AxMSFlexGridLib.AxMSFlexGrid.set_ColWidth(Int32 index, Int32 colWidth)
           at RemAlert.frmRemAlert.frmRemAlert_Load(Object eventSender, EventArgs eventArgs) in E:\E-disk\dev\VB8\RemAlert\RemAlert.NET\RemAlert.vb:line 70
           at System.Windows.Forms.Form.OnLoad(EventArgs e)
           at System.Windows.Forms.Form.SetVisibleCore(Boolean value)
           at System.Windows.Forms.Control.set_Visible(Boolean value)
           at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
           at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
           at System.Windows.Forms.Application.Run(Form mainForm)
           at RemAlert.frmRemAlert.Main() in E:\E-disk\dev\VB8\RemAlert\RemAlert.NET\RemAlert.Designer.vb:line 1
           at System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)
           at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
           at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
           at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
           at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
           at System.Threading.ThreadHelper.ThreadStart()
      InnerException:

    I'm beginning to feel like I'm playing some video game; I wonder how many dragons remain to be slain.

    Price Buhrman

  • Friday, March 16, 2012 9:37 PM
     
     

    The error number doesn't have a meaning for me. I've searched the web and there are only very few hits. In my upgraded test project, the line does not throw an exception. I've searched the C++ header files for that error number or the lower part (753A or 30010 decimal). Is it possible that any accessibility feature is enabled? That's pure speculation because the line I found is

      const long UIA_IsEnabledPropertyId = 30010;

    and that is related to the Accessibility part of the Windows documentation. However, I think it has no relation, but you never know...


    Armin

  • Friday, March 16, 2012 9:47 PM
     
     

    Forget what I wrote. Sometimes it's really simple. Error number 30010 (constant name is flexerrVB30010) is part of the flexgrid error reference, and it means "the specified column value is invalid". So I think either the column index or the width is invalid.

    EDIT: And if you search in the VB6 documentation for 30010, you'll find the "List of Trappable Errors for Visual Basic 4.0" from 1996. :-) It contains "30010 Invalid Column Value"


    Armin

  • Saturday, March 17, 2012 7:17 PM
     
     

    Are your tests run against AxMSFlexGrid or MSFlexGrid? Their properties are substantially different, and the former, which the Upgrade Wizard supplied me with, has no Col.. properties and its Cell.. properties are all read-only.

    The .set_ColWidth(i,j) statement fails in my VS 2010 IDE for the values 1000, 100, 10, and 1, whether passed as literals or in Integer variables.

    The Upgrade-generated globals in my form1.vb are the following:

        'Option Strict Off
        'Option Explicit On
        'Imports VB = Microsoft.VisualBasic
        '(form1) Inherits System.Windows.Forms.Form

    There is no Class reference to AxMSFlexGridLib, and when I open the Object Browser, I find both varieties of FlexGrid Lib and Control listed, each with a host of subsumed objects. The set_ and get_ objects appear to be Functions rather than properties.

    Price Buhrman

  • Saturday, March 17, 2012 8:23 PM
     
     Answered

    Here it doesn't fail with any value.

    In VB6, the type is always MSFlexGrid. After upgrading, the type is AxMSFlexGridLib.AxMSFlexGrid. As I did not change anything, it is still AxMSFlexGrid.

    How is the failing control declared in your project? Here it is

       Public WithEvents MSFlexGrid1 As AxMSFlexGridLib.AxMSFlexGrid

    Yes, set_* get_* are methods, not properties.

    The VB IDE is not quite clear about the data types. Ildasm shows:

    Interop.MSFlexGridlib.dll:

    • Interface IMSFlexGrid
    • Interface DMSFlexGridEvents_Events
    • Interface MSFlexGrid: Implements IMSFlexGrid, DMSFlexGridEvents_Events
    • Class MSFlexGridClass: Implements IMSFlexGrid, DMSFlexGridEvents_Events, MSFlexGrid

    AXInterop.MSFlexGridLib.dll:

    • AxMSFlexGrid: Inherits System.Windows.Forms.AxHost

    In that small sample project, the reference to the former Dll is not required.

    I have no knowledge about why two Dlls are generated.


    Armin

    • Marked As Answer by BuhrmanP Sunday, March 18, 2012 6:41 PM
    •  
  • Sunday, March 18, 2012 6:13 PM
     
     

    The Public WithEvents is among my Update-generated declarations, in project.Designer.vb, as are the following:

            Me.MSFlexGrid1 = New AxMSFlexGridLib.AxMSFlexGrid()

            Me.MSFlexGrid1.CausesValidation = False
            Me.MSFlexGrid1.Location = New System.Drawing.Point(16, 64)
            Me.MSFlexGrid1.Name = "MSFlexGrid1"
            Me.MSFlexGrid1.OcxState = CType(resources.GetObject("MSFlexGrid1.OcxState"), System.Windows.Forms.AxHost.State)
            Me.MSFlexGrid1.Size = New System.Drawing.Size(593, 329)
            Me.MSFlexGrid1.TabIndex = 3               

    Price Buhrman

  • Sunday, March 18, 2012 6:41 PM
     
     

    It wasn't the width value of the  set_ reference, it was the first argument value! I had defined my grid as having just one column, and was trying to set the width of column ONE. I had heard that Basic was moving more into zero-origin for everything countable, such as character position in strings, but I wasn't thinking of that in this problem.

    I'm back up to speed now. Although the fix for my problem wasn't supplied here, the continuing dialog kept me sharply focused on the right spot. I think I'm justified in flagging Armin's last post as "Answer".

    Price Buhrman

  • Sunday, March 18, 2012 6:41 PM
     
     

    There's nothing more I could add to this topic.


    Armin

  • Tuesday, May 29, 2012 6:45 PM
     
     

    I am starting to migrate a project to from VS2008 to VS2010. This is a C# project, but contains a lot of old VB forms and controls. The first problem I am tackling is a COM error "Class not registered (Exception from HRESULT: 0x80040154 (REGDB_E_CLASSNOTREG))". The failure is on the 3rd line.

    1)  private AxMSFlexGridLib.AxMSFlexGrid fgImportTrussInfo;

    2) this.fgImportTrussInfo = new AxMSFlexGridLib.AxMSFlexGrid();

    3) ((System.ComponentModel.ISupportInitialize)(this.fgImportTrussInfo)).EndInit();

    It seems that AxInterop.MSFlexGridLib.dll is not registered. When I manually try to register this dll, it also fails. However, code recognizes AxMSFlexGridLib.AxMSFlexGrid

    I will appreciate any help you can provide.

    Thank you,

    Saleem


    M. Saleem Yusuf