locked
Why does Designer compiled code require alteration, especially for DataGridView? RRS feed

  • Question

  • VB.net 2010 windows forms application:

    Why does the compiler compile with code that requires subsequent alteration?
    For example, in the form sub InitializeComponent():
      system.Windows.Forms.Button() requires alteration to global.system.Windows.Forms.Button()
         or alteration to Button().There are 83 alterations for this.
       system.Drawing.Point(488, 288) requires alteration to Drawing.Point(488, 288).
       system.ComponentModel.ISupportInitialize).BeginInit()
         requires alteration to ISupportInitialize).BeginInit()
    and in the form designer.vb:
       system.Windows.Forms.DataGridView requires alteration to DataGridView.

    The .vb and .designer.vb are preceded by:
    Imports System.Drawing
    Imports System.Drawing.Design
    Imports System.ComponentModel
    Imports System.Windows.Forms


    In addition, I have found that the sub InitializeComponent() requires:
      isInitializing = True
      isInitializing = false
    statements enclosing the sub statements.
    These 2 statements are deleted when the sub is recompiled, and have to be reinserted.

    The above 2 statements are requied enclosing the sub form_load.
    In using DataGridView,which uses the CellValueChanged event, I have found that the statement:
      If isInitializing = True Then Exit Sub
    is required at the start of the CellValueChanged event, and that all alteration code and cell cursor movement should be in this event.
        Microsoft warns only about comboboxes firing during form initialisation.

    I have found that there is little discussion on the DataGridView control in these forums,
    and I hope this discussion will help others.

     David Macpherson.


    David W. Macpherson

    Sunday, April 8, 2012 7:21 AM

Answers

  • It uses Protected OverLoads, not Protected Overrides.

    So it seems definitively not to the expected generated code. Could it be something that was created using an ealier version and upgraded to VS 2010 ? Or have you changed this earlier ? Generated code should never be updated.

    What if you disable code analysis to first make sure your code works as expected without being overwhelmed with those warnings. Then you can enable it at a later time when you have some time at your disposal to fix these issues.

    For example to remove CA1063, you'll have  to change "Protected Overloads" to "Protected Overrides" for Dispose methods...

    This is a middle sized "translation". Translation from what to what ? Have you used some code source translator to translate this code ? Please clairy if yhis code were ONLY created by the VS 2010 designer (or this is a port from an earlier VS version ?)


    Please always mark whatever response solved your issue so that the thread is properly marked as "Answered".

    • Marked as answer by David MacP Thursday, April 12, 2012 12:00 PM
    Wednesday, April 11, 2012 12:12 PM

All replies

  • Hi,

    I never saw or heard about this issue. The designer generated code doesn't include any Imports (as it uses full names). Which template are you using ? Are you sure you don't use a custom template ? Also the designer generated code shouldn't be altered as you'll loose all changes when it is regenerated.

    Could it be that you created a "system" namespace ?

    I would suggest to create a new project, add a button and a datagridview and run the app. If it fails, tell us what is the error you get. Here it works fine. The generated code I get for this is :

    <Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _
    Partial Class Form1
        Inherits System.Windows.Forms.Form
    
        'Form overrides dispose to clean up the component list.
        <System.Diagnostics.DebuggerNonUserCode()> _
        Protected Overrides Sub Dispose(ByVal disposing As Boolean)
            Try
                If disposing AndAlso components IsNot Nothing Then
                    components.Dispose()
                End If
            Finally
                MyBase.Dispose(disposing)
            End Try
        End Sub
    
        'Required by the Windows Form Designer
        Private components As System.ComponentModel.IContainer
    
        'NOTE: The following procedure is required by the Windows Form Designer
        'It can be modified using the Windows Form Designer.  
        'Do not modify it using the code editor.
        <System.Diagnostics.DebuggerStepThrough()> _
        Private Sub InitializeComponent()
            Me.Button1 = New System.Windows.Forms.Button()
            Me.DataGridView1 = New System.Windows.Forms.DataGridView()
            CType(Me.DataGridView1, System.ComponentModel.ISupportInitialize).BeginInit()
            Me.SuspendLayout()
            '
            'Button1
            '
            Me.Button1.Location = New System.Drawing.Point(114, 184)
            Me.Button1.Name = "Button1"
            Me.Button1.Size = New System.Drawing.Size(75, 23)
            Me.Button1.TabIndex = 0
            Me.Button1.Text = "Button1"
            Me.Button1.UseVisualStyleBackColor = True
            '
            'DataGridView1
            '
            Me.DataGridView1.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize
            Me.DataGridView1.Location = New System.Drawing.Point(60, 53)
            Me.DataGridView1.Name = "DataGridView1"
            Me.DataGridView1.Size = New System.Drawing.Size(240, 150)
            Me.DataGridView1.TabIndex = 1
            '
            'Form1
            '
            Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 13.0!)
            Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
            Me.ClientSize = New System.Drawing.Size(284, 262)
            Me.Controls.Add(Me.DataGridView1)
            Me.Controls.Add(Me.Button1)
            Me.Name = "Form1"
            Me.Text = "Form1"
            CType(Me.DataGridView1, System.ComponentModel.ISupportInitialize).EndInit()
            Me.ResumeLayout(False)
    
        End Sub
        Friend WithEvents Button1 As System.Windows.Forms.Button
        Friend WithEvents DataGridView1 As System.Windows.Forms.DataGridView
    
    End Class


    Please always mark whatever response solved your issue so that the thread is properly marked as "Answered".



    Sunday, April 8, 2012 8:35 AM
  • Just to confirm I can break the designer generated code if I create a System namespace. The designer code uses System.xxx. If you create your own System namespace it will search YourApp.System.xxx and won't find any more what is in Global.System.xxx (and you have then to explicitely use Global.System so that it doesn't search in YourApp.System).

    I would just avoid to create a System namespace...


    Please always mark whatever response solved your issue so that the thread is properly marked as "Answered".




    Sunday, April 8, 2012 8:41 AM
  • I have found that there is little discussion on the DataGridView control in these forums,
    and I hope this discussion will help others.

     David Macpherson.


    David W. Macpherson

    http://social.msdn.microsoft.com/Forums/en-US/winforms/threads   Windows Forms General Forum

    Try that one for discussing issues with Form controls.

    Rudy   =8^D


    Mark the best replies as answers. "Fooling computers since 1971."

    http://thesharpercoder.blogspot.com/

    Sunday, April 8, 2012 6:07 PM
  • Patrice,
    Thank you for your reply.

    I am using MVS2010 Ultimate with the 6 hotfixes, security update & SP1.

    I used the Windows Forms Application template, not a custom nameplate.
    I have not created a "system" namespace.

    The suggested new project creates form1.designer.vb file identical with yours.

    When I delete the imports files from my Affinity designer, I get an error with:
      Friend WithEvents DataGridView1 As DataGridView
    I get more than 4 recommendations, the first of which is "Import 'System.Windows.Forms'"
    This is why I added the Imports statements to these files.
    What is your comment?

    Among the 360 warnings I get after running, the following related to designer or system code
     require comment:

    Warning 35 CA1063 : Microsoft.Design : Ensure that 'frmChangeScale.Dispose(Boolean)'
     is declared as protected, virtual, and unsealed.
     C:\AffinityN\frmChangeScale.Designer.vb 13 AffinityN

    Warning 111 CA2202 : Microsoft.Usage : Object 'Me' can be disposed more than once
    in method 'frmDutyselect1.Dispose(Boolean)'. To avoid generating a
    System.ObjectDisposedException you should not call Dispose more than one time on an object.
    : Lines: 18 C:\AffinityN\frmDutyselect1.Designer.vb 18 AffinityN
     

    Warning 43 CA2213 : Microsoft.Usage : 'frmCurve' contains field 'frmCurve.BlackBrush'
    that is of IDisposable type: 'SolidBrush'. Change the Dispose method on 'frmCurve' to call
    Dispose or Close on this field. C:\AffinityN\frmCurve.Designer.vb 14 AffinityN
    My comment is that brushes and pens, generated in form_load, is disposed in the form closing event.

    Warning 360 CA1823 : Microsoft.Performance : It appears that field 'ComponentResourceManager._type' is never used or is only ever assigned to. Use this field or remove it. C:\AffinityN\ComponentResourceManager.vb 5 AffinityN

    Warning 1 Creating an instance of the COM component with CLSID
     {972ABB3F-09C2-11D5-898E-0050DA7509CB} from the IClassFactory failed due to the following error:
     80004003.  0 0 
    My request on this, is please give me a method of finding this com component.

    Regards,

    David.


    David W. Macpherson

    Monday, April 9, 2012 3:20 AM
  • Not sure what you meant with "I delete the imports files from my Affinity designer" ?

    Also It seems you have :

    Friend WithEvents DataGridView1 As DataGridView ' So DataGridView is not known if System.Windows.Forms is not imported

    I have :

    Friend WithEvents DataGridView1 As System.Windows.Forms.DataGridView ' So importing System.Windows.Forms is not needed

    You should be able to find the COM component using regedit and by looking at HKEY_CLASSES_ROOT\CLSID (I don't see this one here).

    For example I don't have CA1063 with the default designer generated file. It uses "Protected Overrides" for the Dispose method. What is the one used in n your frmChangeScale.Designer.vb file ?

    My approach would be :

    - to create a dummy new project to use as a reference for generated code
    - I would set Code Analysis to the minimal level and would fix issues before going to the next level
    - try to fix perhaps first the CAXXXX for which you have the greater number of warnings
    - and post perhaps about a warning at a time if you need help.


    Please always mark whatever response solved your issue so that the thread is properly marked as "Answered".

    Monday, April 9, 2012 12:52 PM
  • Patrice,
    Thank you for your reply.

    I am using MVS2010 Ultimate with the 6 hotfixes, security update & SP1.

    I used the Windows Forms Application template, not a custom nameplate.
    I have not created a "system" namespace.

    The suggested new project creates form1.designer.vb file identical with yours.

    When I delete the imports files from my Affinity designer, I get an error with:
      Friend WithEvents DataGridView1 As DataGridView
    I get more than 4 recommendations, the first of which is "Import 'System.Windows.Forms'"
    This is why I added the Imports statements to these files.
    What is your comment?

    Among the 360 warnings I get after running, the following related to designer or system code
     require comment:


    David W. Macpherson

    Are you using a tool similar to FxCop? I have no idea what "Affinity" might be. So, I am going to ignore it. You previously described behaviors that are not exhibited by types in the WinForms namespace.

    Rudy    =8^D


    Mark the best replies as answers. "Fooling computers since 1971."

    http://thesharpercoder.blogspot.com/


    • Edited by Rudedog2 Monday, April 9, 2012 9:39 PM
    Monday, April 9, 2012 9:38 PM
  • See this zip for the reply.

    Patrice,
    Here is the frmChangeScale.designer.vb file, on which I tested removing the imports statement.
    It uses Protected OverLoads, not Protected Overrides.
    
    Imports System.Drawing.Design
    Imports System.Windows.Forms
    Imports System.Windows.Forms.Form
    Imports System.ComponentModel
    <Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> Partial Class frmChangeScale
    #Region "Windows Form Designer generated code "
        <DebuggerNonUserCodeAttribute()> Public Sub New()
            MyBase.New()
            'This call is required by the Windows Form Designer.
            InitializeComponent()
        End Sub
        'Form overrides dispose to clean up the component list.
        <DebuggerNonUserCodeAttribute()> Protected Overloads Sub Dispose(ByVal Disposing As Boolean)
            If Disposing Then
                If Not components Is Nothing Then
                    Dispose(Disposing)
                End If
            End If
            Dispose(Disposing)
        End Sub
        'Required by the Windows Form Designer
        Private components As Global.System.ComponentModel.IContainer 'requires global
        Public WithEvents ToolTip1 As Windows.Forms.ToolTip
        Public WithEvents cmdDone As Windows.Forms.Button
        Friend WithEvents dgvChangeScale As Windows.Forms.DataGridView
        Friend WithEvents lblData As Windows.Forms.Label
        Friend WithEvents lblGraph As Windows.Forms.Label
        Friend WithEvents Col0 As Windows.Forms.DataGridViewTextBoxColumn
        Friend WithEvents Col1 As Windows.Forms.DataGridViewTextBoxColumn
        Friend WithEvents Col2 As Windows.Forms.DataGridViewTextBoxColumn
        Friend WithEvents Col3 As Windows.Forms.DataGridViewTextBoxColumn
        Friend WithEvents Col4 As Windows.Forms.DataGridViewTextBoxColumn
        Friend WithEvents Col5 As Windows.Forms.DataGridViewTextBoxColumn
        Friend WithEvents Col6 As Windows.Forms.DataGridViewTextBoxColumn
        Friend WithEvents Col7 As Windows.Forms.DataGridViewTextBoxColumn
        Friend WithEvents Col8 As Windows.Forms.DataGridViewTextBoxColumn
        Friend WithEvents DataGridView1 As DataGridView
        'Public WithEvents txtChangeScaleEdit As Windows.Forms.TextBox
        'Friend WithEvents fgChangescale As MSFlexGridLib.MSFlexGrid
        'NOTE: The following procedure is required by the Windows Form Designer
        'It can be modified using the Windows Form Designer.
        'Do not modify it using the code editor.
    
    
    #End Region
    
    
    End Class
    
    Also for reference, the frmDataEnter_load:
    
    Option Strict Off
    Option Explicit On
    Option Compare Text
    Imports System.Drawing
    Imports System.Windows.Forms.Form
    Imports System.Windows.Forms
    
    Public Class frmChangeScale
        Inherits Windows.Forms.Form
        'frmChangeScale v4 220110 handle scale exponents v3 010108 v2 270506
        'Option Base '1120211
        Shared WithEvents frmChangeScale As New Form '171111 withevents
        Dim IsInitializing As Boolean = True
        Dim LastRow As Short
        Dim FirstRow As Short
        'Dim FirstCol As Short = 4
        Dim SkipRow As Short '010108
        Dim UpdateFail As Boolean = False
        Dim blnUpdating As Boolean = False
    
        Private Sub frmChangeScale_FormClosing(sender As Object, e As FormClosingEventArgs) Handles Me.FormClosing
            dgvChangeScale.Dispose()
        End Sub 'Dim ScaleChanged As Boolean = False
    
        Public Sub frmChangeScale_Load(ByVal eventSender As Global.System.Object, ByVal e As Global.System.EventArgs) Handles MyBase.Load
            'v3 260510 H,P exponent added without if 'v2 210110 Q exponent added
            Dim I, I1 As Short
            Dim strz As String
            ' Dim e As Graphics = Me.CreateGraphics()
    
            IsInitializing = True
            On Error GoTo Trap
            MessageTitle = "AffinityN - manual scale change"
            UpDateData_gNpsh(1, Inout) 'rewrite this
            If Inout = 2 Then strz = "Output" Else strz = "Data"
            Me.Text = "Manual Change Scales for " & strz & " Curves #" & Firstcurve(Inout) & " to #" & Lastcurve(Inout) & ", click if blue to edit, R arrow to do." '020108
            For I = Qvar - 1 To Pvar - 1 'expand exponent
                If I = Evar - 1 Then GoTo Nxt
                G(1, I, Inout) = G(1, I, Inout) * 10 ^ G(4, I, Inout) 'min
                G(2, I, Inout) = G(2, I, Inout) * 10 ^ G(4, I, Inout) 'max
                G(3, I, Inout) = G(3, I, Inout) * 10 ^ G(4, I, Inout) 'step
                G(6, I, Inout) = G(6, I, Inout) * 10 ^ G(4, I, Inout) 'range
    Nxt:
            Next I
            frmChangeScale.Width = 624
            frmChangeScale.Height = 392
            With dgvChangeScale
                .RowCount = 8
                .ColumnCount = 9
                '.Rows(0).Cells(4) = Nothing
                '.Rows(0).Cells(5) = Nothing
                '       0           1          2         3         4         5         6        7         8
                '  "^  Scale   |^  Unit   |^  Min   |^  Max   |^  Min   |^  Max   |^  Step  |^ # Steps|^ -1=nil "
                .Rows(1).Cells(0).Value = "Speed"
                .Rows(2).Cells(0).Value = "Flow"
                .Rows(3).Cells(0).Value = "Head"
                .Rows(4).Cells(0).Value = "Efficiency"
                .Rows(5).Cells(0).Value = "Power"
                .Rows(6).Cells(0).Value = "Npsh"
                .Rows(7).Cells(0).Value = "KWh/KL"
                '.(0, 1).value = "rpm" 'does not work
    
                For I = 1 To 7 'variable in row
                    If blnReIso = True Then
                        For I1 = 1 To 6
                            G(I1, I, Inout) = G_Old(I1, I, 1)
                        Next I1
                    End If
                    Select Case I 'units
                        Case 1 : strz = "rpm"
                        Case 2, 3 : strz = Unit(U(Inout, I - 1, Inout)) 'Q,H
                        Case 4 : strz = "%"
                        Case 5 : strz = Unit(U(Inout, 3, Inout)) 'P
                        Case 6 : strz = Unit(U(Inout, 2, Inout)) 'Npsh
                        Case Else : strz = "" 'KWh/Kl
                    End Select
                    .Rows(I).Cells(1).Value = strz 'unit .set_TextMatrix(I, 1, strz) 'row,col; variable
                    .Rows(I).Cells(7).Value = G0(5, I).ToString("F0") ' .set_TextMatrix(I, 7, String.Format(G0(5, I), "###0")) 'scale # steps
                    .Rows(I).Cells(8).Value = G(5, I, Inout).ToString("F0") ' .set_TextMatrix(I, 8, G(5, I, Inout)) 'Scale status
                    Select Case I
                        Case 1 'speed
                            .Rows(I).Cells(2).Value = String.Format(Data_g(1, I, Inout), "#####0") ' .set_TextMatrix(I, 2, String.Format(Data_g(1, I, Inout), "#####0")) 'data_g min
                            .Rows(I).Cells(3).Value = String.Format(Data_g(2, I, Inout), "#####0") ' .set_TextMatrix(I, 3, String.Format(Data_g(2, I, Inout), "#####0")) 'data_g max
                            .Rows(I).Cells(4).Value = String.Format(G(1, I, Inout), "#####0") ' .set_TextMatrix(I, 4, String.Format(G(1, I, Inout), "#####0")) 'min
                            .Rows(I).Cells(5).Value = String.Format(G(2, I, Inout), "#####0") ' .set_TextMatrix(I, 5, String.Format(G(2, I, Inout), "#####0")) 'max
                            .Rows(I).Cells(6).Value = String.Format(G(3, I, Inout), "####0") '  .set_TextMatrix(I, 6, String.Format(G(3, I, Inout), "####0")) 'step
                        Case 2 'Q
                            .Rows(I).Cells(2).Value = Data_g(1, I, Inout).ToString("F0") '.set_TextMatrix(I, 2, String.Format(Data_g(1, I, Inout), "###,##0")) 'data_g min
                            .Rows(I).Cells(3).Value = Data_g(2, I, Inout).ToString("F0") ' .set_TextMatrix(I, 3, String.Format(Data_g(2, I, Inout), "###,##0")) 'data_g max
                            .Rows(I).Cells(4).Value = G(1, I, Inout).ToString("F0") ' .set_TextMatrix(I, 4, String.Format(G(1, I, Inout), "###,##0")) 'min
                            .Rows(I).Cells(5).Value = G(2, I, Inout).ToString("F0") ' .set_TextMatrix(I, 5, String.Format(G(2, I, Inout), "###,##0")) 'max
                            .Rows(I).Cells(6).Value = G(3, I, Inout).ToString("F0") ' .set_TextMatrix(I, 6, String.Format(G(3, I, Inout), "##,##0")) 'step
                        Case 3, 5 'H,P
                            If G(4, I, Inout) <> 0 Then
                                .Rows(I).Cells(2).Value = Data_g(1, I, Inout).ToString("0.0E+00") ' .set_TextMatrix(I, 2, String.Format(Data_g(1, I, Inout), "###,##0.0")) 'data_g min
                                .Rows(I).Cells(3).Value = Data_g(2, I, Inout).ToString("0.0E+00") ' .set_TextMatrix(I, 3, String.Format(Data_g(2, I, Inout), "###,##0.0")) 'data_g max
                                .Rows(I).Cells(4).Value = G(1, I, Inout).ToString("0.0E+00") ' .set_TextMatrix(I, 4, String.Format(G(1, I, Inout), "###,##0")) 'min
                                .Rows(I).Cells(5).Value = G(2, I, Inout).ToString("0.0E+00") '.set_TextMatrix(I, 5, String.Format(G(2, I, Inout), "###,##0")) 'max
                                .Rows(I).Cells(6).Value = G(3, I, Inout).ToString("0.0E+00") ' .set_TextMatrix(I, 6, String.Format(G(3, I, Inout), "##,##0")) 'step
                            Else
                                .Rows(I).Cells(2).Value = Data_g(1, I, Inout).ToString("F0") ' .set_TextMatrix(I, 2, String.Format(Data_g(1, I, Inout), "###,##0.0")) 'data_g min
                                .Rows(I).Cells(3).Value = Data_g(2, I, Inout).ToString("F0") ' .set_TextMatrix(I, 3, String.Format(Data_g(2, I, Inout), "###,##0.0")) 'data_g max
                                .Rows(I).Cells(4).Value = G(1, I, Inout).ToString("F0") ' .set_TextMatrix(I, 4, String.Format(G(1, I, Inout), "###,##0")) 'min
                                .Rows(I).Cells(5).Value = G(2, I, Inout).ToString("F0") '.set_TextMatrix(I, 5, String.Format(G(2, I, Inout), "###,##0")) 'max
                                .Rows(I).Cells(6).Value = G(3, I, Inout).ToString("F0") ' .set_TextMatrix(I, 6, String.Format(G(3, I, Inout), "##,##0")) 'step
                            End If
                        Case 4 'effy
                            .Rows(I).Cells(2).Value = Data_g(1, I, Inout).ToString("F1") ' .set_TextMatrix(I, 2, String.Format(Data_g(1, I, Inout), "#0.0")) 'data_g min
                            .Rows(I).Cells(3).Value = Data_g(2, I, Inout).ToString("F1") ' .set_TextMatrix(I, 3, String.Format(Data_g(2, I, Inout), "#0.0")) 'data_g max
                            .Rows(I).Cells(4).Value = G(1, I, Inout).ToString("F0") ' .set_TextMatrix(I, 4, String.Format(G(1, I, Inout), "#0")) 'min
                            .Rows(I).Cells(5).Value = G(2, I, Inout).ToString("F0") ' .set_TextMatrix(I, 5, String.Format(G(2, I, Inout), "#0")) 'max
                            .Rows(I).Cells(6).Value = G(3, I, Inout).ToString("F0") ' .set_TextMatrix(I, 6, String.Format(G(3, I, Inout), "#0")) 'step
                        Case 6 'Npsh
                            If G(2, I, Inout) < 3 Then
                                .Rows(I).Cells(2).Value = Data_g(1, I, Inout).ToString("F0") ' .set_TextMatrix(I, 2, String.Format(Data_g(1, I, Inout), "###0.0#")) 'data_g min
                                .Rows(I).Cells(3).Value = Data_g(2, I, Inout).ToString("F0") ' .set_TextMatrix(I, 3, String.Format(Data_g(2, I, Inout), "#0.0#")) 'data_g max
                                .Rows(I).Cells(4).Value = G(1, I, Inout).ToString("F0") ' .set_TextMatrix(I, 4, String.Format(G(1, I, Inout), "#0.0#")) 'min
                                .Rows(I).Cells(5).Value = G(2, I, Inout).ToString("F0") ' .set_TextMatrix(I, 5, String.Format(G(2, I, Inout), "#0.0#")) 'max
                                .Rows(I).Cells(6).Value = G(3, I, Inout).ToString("F0") ' .set_TextMatrix(I, 6, String.Format(G(3, I, Inout), "#0.0#")) 'step
                            ElseIf G(2, I, Inout) < 10 Then '170811
                                .Rows(I).Cells(2).Value = Data_g(1, I, Inout).ToString("F0") ' .set_TextMatrix(I, 2, String.Format(Data_g(1, I, Inout), "###0.0#")) 'data_g min
                                .Rows(I).Cells(3).Value = Data_g(2, I, Inout).ToString("F0") ' .set_TextMatrix(I, 3, String.Format(Data_g(2, I, Inout), "#0.0#")) 'data_g max
                                .Rows(I).Cells(4).Value = G(1, I, Inout).ToString("F0") ' .set_TextMatrix(I, 4, String.Format(G(1, I, Inout), "#0.0#")) 'min
                                .Rows(I).Cells(5).Value = G(2, I, Inout).ToString("F0") ' .set_TextMatrix(I, 5, String.Format(G(2, I, Inout), "#0.0#")) 'max
                                .Rows(I).Cells(6).Value = G(3, I, Inout).ToString("F0") ' .set_TextMatrix(I, 6, String.Format(G(3, I, Inout), "#0.0#")) 'step
                            Else
                                .Rows(I).Cells(2).Value = Data_g(1, I, Inout).ToString("F0") ' .set_TextMatrix(I, 2, String.Format(Data_g(1, I, Inout), "###0")) 'data_g min
                                .Rows(I).Cells(3).Value = Data_g(2, I, Inout).ToString("F0") ' .set_TextMatrix(I, 3, String.Format(Data_g(2, I, Inout), "###0")) 'data_g max
                                .Rows(I).Cells(4).Value = G(1, I, Inout).ToString("F0") ' .set_TextMatrix(I, 4, String.Format(G(1, I, Inout), "####0")) 'min
                                .Rows(I).Cells(5).Value = G(2, I, Inout).ToString("F0") ' .set_TextMatrix(I, 5, String.Format(G(2, I, Inout), "####0")) 'max
                                .Rows(I).Cells(6).Value = G(3, I, Inout).ToString("F0") ' .set_TextMatrix(I, 6, String.Format(G(3, I, Inout), "####0")) 'step
                            End If
                    End Select
                Next I
                .Columns(0).ReadOnly = True 'below Header'del 181111 in design
                .Columns(1).ReadOnly = True 'Unit
                .Columns(2).ReadOnly = True 'Data Min
                .Columns(3).ReadOnly = True 'Data max
                .Columns(7).ReadOnly = True ' # steps
                .Rows(0).ReadOnly = True 'header
                .Rows(7).ReadOnly = True 'KWh/KL not implemented
                For I = 4 To 8
                    If I = 7 Then GoTo NxtI0
                    .Rows(7).Cells(I).Style.BackColor = Color.Silver 'kwh/kl
    NxtI0:      Next
                .Rows(2).Cells(8).ReadOnly = True 'Q status
                .Rows(2).Cells(8).Style.BackColor = Color.Silver 'Q
                If Isofit(Inout) > 1 Then
                    .Rows(3).Cells(8).ReadOnly = True 'H status
                    .Rows(3).Cells(8).Style.BackColor = Color.Silver 'H
                    .Rows(1).ReadOnly = True 'speed
                    .Rows(4).ReadOnly = True 'effy
                    For I = 4 To 8
                        If I = 7 Then GoTo NxtI
                        .Rows(1).Cells(I).Style.BackColor = Color.Silver 'speed
                        .Rows(4).Cells(I).Style.BackColor = Color.Silver 'effy
    NxtI:           Next
                Else
                    .Rows(3).Cells(8).ReadOnly = False 'H status
                    .Rows(3).Cells(8).Style.BackColor = Color.LightSkyBlue 'H
                    .Rows(1).ReadOnly = False 'speed
                    .Rows(4).ReadOnly = False 'effy
                    For I = 4 To 8
                        If I = 7 Then GoTo NxtI1
                        .Rows(1).Cells(I).Style.BackColor = Color.LightSkyBlue 'speed
                        .Rows(4).Cells(I).Style.BackColor = Color.LightSkyBlue 'effy
    NxtI1:          Next
                End If
                .CurrentCell = .Rows(3).Cells(5) 'H max
                .EditMode = DataGridViewEditMode.EditOnKeystroke
                .SelectionMode = DataGridViewSelectionMode.CellSelect
            End With
            '    UPGRADE_ISSUE: Form property frmChangeScale.FillStyle was not upgraded. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="CC4C7EC0-C903-48FC-ACCC-81861D12DA4A"'
            ' dgvChangeScale.FillStyle = MSFlexGridLib.FillStyleSettings.flexFillSingle
            ' .Row = 2
            ' .Col = 4 '#cols=8,#fixedcols=4
            If Inout = 1 Then
                lblData.Text = "Data"
            Else
                lblData.Text = "Data as output"
            End If
            ChangeScaleLoaded = Inout
            ' ScaleChanged = False
            UpdateFail = False
    
            If Silent = 1 Then My.Forms.frmCurve.Plot_rcl() ' to display for option to alter scales
            With Me
                If My.Forms.frmCurve.Visible = True Then
                    .Left = My.Forms.frmCurve.Right + 5
                    .Top = My.Forms.frmCurve.Top + 200
                End If
            End With
    Trap:
            If ErrNumber <> 0 Then Exit Sub
            If Err.Number <> 0 Then
                ErrNumber = Err.Number
                Msg = "frmChangescale.load error " & Err.Description & " at line " & Err.Erl
                'Debug.print(Msg)
                Response = MsgBox(Msg, MsgBoxStyle.OkOnly, MessageTitle)
                If Response = MsgBoxResult.Ok Then
                    Exit Sub
                End If
            End If
            IsInitializing = False
            'global.print;"frmChangeScale loaded"
        End Sub
    
    and here is the sub InitializeComponent, which appears in the .vb not in the designer.
    In this sub, I did not have to use isinitializing = true before and isinitializing = false in the sub,
    whereas in a similar form I had to. I traced the code in the similar form which made this necessary, but have forgotten the details.
    
        Private Sub InitializeComponent()
            Dim DataGridViewCellStyle1 As DataGridViewCellStyle = New DataGridViewCellStyle()
            Dim DataGridViewCellStyle10 As DataGridViewCellStyle = New DataGridViewCellStyle()
            Dim DataGridViewCellStyle11 As DataGridViewCellStyle = New DataGridViewCellStyle()
            Dim DataGridViewCellStyle2 As DataGridViewCellStyle = New DataGridViewCellStyle()
            Dim DataGridViewCellStyle3 As DataGridViewCellStyle = New DataGridViewCellStyle()
            Dim DataGridViewCellStyle4 As DataGridViewCellStyle = New DataGridViewCellStyle()
            Dim DataGridViewCellStyle5 As DataGridViewCellStyle = New DataGridViewCellStyle()
            Dim DataGridViewCellStyle6 As DataGridViewCellStyle = New DataGridViewCellStyle()
            Dim DataGridViewCellStyle7 As DataGridViewCellStyle = New DataGridViewCellStyle()
            Dim DataGridViewCellStyle8 As DataGridViewCellStyle = New DataGridViewCellStyle()
            Dim DataGridViewCellStyle9 As DataGridViewCellStyle = New DataGridViewCellStyle()
            Me.cmdDone = New Button()
            Me.dgvChangeScale = New DataGridView()
            Me.Col0 = New DataGridViewTextBoxColumn()
            Me.Col1 = New DataGridViewTextBoxColumn()
            Me.Col2 = New DataGridViewTextBoxColumn()
            Me.Col3 = New DataGridViewTextBoxColumn()
            Me.Col4 = New DataGridViewTextBoxColumn()
            Me.Col5 = New DataGridViewTextBoxColumn()
            Me.Col6 = New DataGridViewTextBoxColumn()
            Me.Col7 = New DataGridViewTextBoxColumn()
            Me.Col8 = New DataGridViewTextBoxColumn()
            Me.lblData = New Label()
            Me.lblGraph = New Label()
            Me.DataGridView1 = New DataGridView()
            CType(Me.dgvChangeScale, ISupportInitialize).BeginInit()
            CType(Me.DataGridView1, ISupportInitialize).BeginInit()
            Me.SuspendLayout()
            '
            'cmdDone
            '
            Me.cmdDone.Location = New Drawing.Point(488, 288)
            Me.cmdDone.Margin = New Padding(6, 6, 4, 4)
            Me.cmdDone.Name = "cmdDone"
            Me.cmdDone.Size = New Drawing.Size(70, 40)
            Me.cmdDone.TabIndex = 2
            Me.cmdDone.Text = "Done"
            Me.cmdDone.UseVisualStyleBackColor = True
            '
            'dgvChangeScale
            '
            Me.dgvChangeScale.AllowUserToAddRows = False
            Me.dgvChangeScale.AllowUserToDeleteRows = False
            Me.dgvChangeScale.AllowUserToResizeColumns = False
            Me.dgvChangeScale.AllowUserToResizeRows = False
            DataGridViewCellStyle1.Alignment = DataGridViewContentAlignment.MiddleCenter
            DataGridViewCellStyle1.Font = New Drawing.Font("Microsoft Sans Serif", 8.25!, Drawing.FontStyle.Regular, Drawing.GraphicsUnit.Point, CType(0, Byte))
            DataGridViewCellStyle1.ForeColor = Drawing.Color.Black
            DataGridViewCellStyle1.SelectionBackColor = Drawing.Color.Gainsboro
            DataGridViewCellStyle1.SelectionForeColor = Drawing.Color.Black
            DataGridViewCellStyle1.WrapMode = DataGridViewTriState.[False]
            Me.dgvChangeScale.AlternatingRowsDefaultCellStyle = DataGridViewCellStyle1
            Me.dgvChangeScale.ClipboardCopyMode = DataGridViewClipboardCopyMode.Disable
            Me.dgvChangeScale.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.DisableResizing
            Me.dgvChangeScale.Columns.AddRange(New DataGridViewColumn() {Me.Col0, Me.Col1, Me.Col2, Me.Col3, Me.Col4, Me.Col5, Me.Col6, Me.Col7, Me.Col8})
            DataGridViewCellStyle10.Alignment = DataGridViewContentAlignment.MiddleCenter
            DataGridViewCellStyle10.BackColor = Drawing.SystemColors.Window
            DataGridViewCellStyle10.Font = New Drawing.Font("Microsoft Sans Serif", 8.25!, Drawing.FontStyle.Regular, Drawing.GraphicsUnit.Point, CType(0, Byte))
            DataGridViewCellStyle10.ForeColor = Drawing.Color.Black
            DataGridViewCellStyle10.SelectionBackColor = Drawing.SystemColors.Highlight
            DataGridViewCellStyle10.SelectionForeColor = Drawing.SystemColors.HighlightText
            DataGridViewCellStyle10.WrapMode = DataGridViewTriState.[False]
            Me.dgvChangeScale.DefaultCellStyle = DataGridViewCellStyle10
            Me.dgvChangeScale.GridColor = Drawing.Color.White
            Me.dgvChangeScale.Location = New Drawing.Point(24, 73)
            Me.dgvChangeScale.MultiSelect = False
            Me.dgvChangeScale.Name = "dgvChangeScale"
            DataGridViewCellStyle11.Alignment = DataGridViewContentAlignment.MiddleLeft
            DataGridViewCellStyle11.BackColor = Drawing.Color.WhiteSmoke
            DataGridViewCellStyle11.Font = New Drawing.Font("Microsoft Sans Serif", 8.25!, Drawing.FontStyle.Regular, Drawing.GraphicsUnit.Point, CType(0, Byte))
            DataGridViewCellStyle11.ForeColor = Drawing.SystemColors.WindowText
            DataGridViewCellStyle11.SelectionBackColor = Drawing.Color.WhiteSmoke
            DataGridViewCellStyle11.SelectionForeColor = Drawing.SystemColors.HighlightText
            DataGridViewCellStyle11.WrapMode = DataGridViewTriState.[True]
            Me.dgvChangeScale.RowHeadersDefaultCellStyle = DataGridViewCellStyle11
            Me.dgvChangeScale.RowHeadersWidthSizeMode = DataGridViewRowHeadersWidthSizeMode.DisableResizing
            Me.dgvChangeScale.ScrollBars = ScrollBars.None
            Me.dgvChangeScale.SelectionMode = DataGridViewSelectionMode.CellSelect
            Me.dgvChangeScale.Size = New Drawing.Size(534, 206)
            Me.dgvChangeScale.TabIndex = 0
            '
            'Col0
            '
            Me.Col0.Frozen = True
            Me.Col0.HeaderText = "Scale"
            Me.Col0.MaxInputLength = 10
            Me.Col0.Name = "Col0"
            Me.Col0.Width = 60
            '
            'Col1
            '
            Me.Col1.AutoSizeMode = DataGridViewAutoSizeColumnMode.None
            DataGridViewCellStyle2.Alignment = DataGridViewContentAlignment.MiddleCenter
            DataGridViewCellStyle2.BackColor = Drawing.Color.Silver
            DataGridViewCellStyle2.Font = New Drawing.Font("Microsoft Sans Serif", 8.25!, Drawing.FontStyle.Regular, Drawing.GraphicsUnit.Point, CType(0, Byte))
            DataGridViewCellStyle2.ForeColor = Drawing.Color.Black
            DataGridViewCellStyle2.SelectionBackColor = Drawing.Color.Silver
            DataGridViewCellStyle2.SelectionForeColor = Drawing.Color.Black
            Me.Col1.DefaultCellStyle = DataGridViewCellStyle2
            Me.Col1.DividerWidth = 1
            Me.Col1.Frozen = True
            Me.Col1.HeaderText = " Unit"
            Me.Col1.MaxInputLength = 10
            Me.Col1.Name = "Col1"
            Me.Col1.Resizable = DataGridViewTriState.[False]
            Me.Col1.SortMode = DataGridViewColumnSortMode.NotSortable
            Me.Col1.Width = 40
            '
            'Col2
            '
            Me.Col2.AutoSizeMode = DataGridViewAutoSizeColumnMode.None
            DataGridViewCellStyle3.Alignment = DataGridViewContentAlignment.MiddleCenter
            DataGridViewCellStyle3.BackColor = Drawing.Color.Silver
            DataGridViewCellStyle3.Font = New Drawing.Font("Microsoft Sans Serif", 8.25!, Drawing.FontStyle.Regular, Drawing.GraphicsUnit.Point, CType(0, Byte))
            DataGridViewCellStyle3.ForeColor = Drawing.Color.Black
            DataGridViewCellStyle3.NullValue = Nothing
            DataGridViewCellStyle3.SelectionBackColor = Drawing.Color.Silver
            DataGridViewCellStyle3.SelectionForeColor = Drawing.Color.Black
            Me.Col2.DefaultCellStyle = DataGridViewCellStyle3
            Me.Col2.DividerWidth = 1
            Me.Col2.Frozen = True
            Me.Col2.HeaderText = "  Min"
            Me.Col2.Name = "Col2"
            Me.Col2.Resizable = DataGridViewTriState.[False]
            Me.Col2.SortMode = DataGridViewColumnSortMode.NotSortable
            Me.Col2.Width = 60
            '
            'Col3
            '
            Me.Col3.AutoSizeMode = DataGridViewAutoSizeColumnMode.None
            DataGridViewCellStyle4.Alignment = DataGridViewContentAlignment.MiddleCenter
            DataGridViewCellStyle4.BackColor = Drawing.Color.Silver
            DataGridViewCellStyle4.Font = New Drawing.Font("Microsoft Sans Serif", 8.25!, Drawing.FontStyle.Regular, Drawing.GraphicsUnit.Point, CType(0, Byte))
            DataGridViewCellStyle4.ForeColor = Drawing.Color.Black
            DataGridViewCellStyle4.NullValue = Nothing
            DataGridViewCellStyle4.SelectionBackColor = Drawing.Color.Silver
            DataGridViewCellStyle4.SelectionForeColor = Drawing.Color.Black
            Me.Col3.DefaultCellStyle = DataGridViewCellStyle4
            Me.Col3.DividerWidth = 3
            Me.Col3.Frozen = True
            Me.Col3.HeaderText = " Max"
            Me.Col3.Name = "Col3"
            Me.Col3.Resizable = DataGridViewTriState.[False]
            Me.Col3.SortMode = DataGridViewColumnSortMode.NotSortable
            Me.Col3.Width = 60
            '
            'Col4
            '
            Me.Col4.AutoSizeMode = DataGridViewAutoSizeColumnMode.None
            DataGridViewCellStyle5.Alignment = DataGridViewContentAlignment.MiddleCenter
            DataGridViewCellStyle5.BackColor = Drawing.Color.LightSkyBlue
            DataGridViewCellStyle5.Font = New Drawing.Font("Microsoft Sans Serif", 8.25!, Drawing.FontStyle.Regular, Drawing.GraphicsUnit.Point, CType(0, Byte))
            DataGridViewCellStyle5.ForeColor = Drawing.Color.Black
            DataGridViewCellStyle5.NullValue = Nothing
            DataGridViewCellStyle5.SelectionBackColor = Drawing.Color.AliceBlue
            DataGridViewCellStyle5.SelectionForeColor = Drawing.Color.Black
            Me.Col4.DefaultCellStyle = DataGridViewCellStyle5
            Me.Col4.DividerWidth = 1
            Me.Col4.Frozen = True
            Me.Col4.HeaderText = "  Min"
            Me.Col4.Name = "Col4"
            Me.Col4.Resizable = DataGridViewTriState.[False]
            Me.Col4.SortMode = DataGridViewColumnSortMode.NotSortable
            Me.Col4.Width = 60
            '
            'Col5
            '
            Me.Col5.AutoSizeMode = DataGridViewAutoSizeColumnMode.None
            DataGridViewCellStyle6.Alignment = DataGridViewContentAlignment.MiddleCenter
            DataGridViewCellStyle6.BackColor = Drawing.Color.LightSkyBlue
            DataGridViewCellStyle6.Font = New Drawing.Font("Microsoft Sans Serif", 8.25!, Drawing.FontStyle.Regular, Drawing.GraphicsUnit.Point, CType(0, Byte))
            DataGridViewCellStyle6.ForeColor = Drawing.Color.Black
            DataGridViewCellStyle6.NullValue = Nothing
            DataGridViewCellStyle6.SelectionBackColor = Drawing.Color.AliceBlue
            DataGridViewCellStyle6.SelectionForeColor = Drawing.Color.Black
            Me.Col5.DefaultCellStyle = DataGridViewCellStyle6
            Me.Col5.DividerWidth = 1
            Me.Col5.Frozen = True
            Me.Col5.HeaderText = "  Max"
            Me.Col5.Name = "Col5"
            Me.Col5.Resizable = DataGridViewTriState.[False]
            Me.Col5.SortMode = DataGridViewColumnSortMode.NotSortable
            Me.Col5.Width = 60
            '
            'Col6
            '
            Me.Col6.AutoSizeMode = DataGridViewAutoSizeColumnMode.None
            DataGridViewCellStyle7.Alignment = DataGridViewContentAlignment.MiddleCenter
            DataGridViewCellStyle7.BackColor = Drawing.Color.LightSkyBlue
            DataGridViewCellStyle7.Font = New Drawing.Font("Microsoft Sans Serif", 8.25!, Drawing.FontStyle.Regular, Drawing.GraphicsUnit.Point, CType(0, Byte))
            DataGridViewCellStyle7.ForeColor = Drawing.Color.Black
            DataGridViewCellStyle7.NullValue = Nothing
            DataGridViewCellStyle7.SelectionBackColor = Drawing.Color.AliceBlue
            DataGridViewCellStyle7.SelectionForeColor = Drawing.Color.Black
            Me.Col6.DefaultCellStyle = DataGridViewCellStyle7
            Me.Col6.DividerWidth = 1
            Me.Col6.Frozen = True
            Me.Col6.HeaderText = "  Step"
            Me.Col6.Name = "Col6"
            Me.Col6.Resizable = DataGridViewTriState.[False]
            Me.Col6.SortMode = DataGridViewColumnSortMode.NotSortable
            Me.Col6.Width = 60
            '
            'Col7
            '
            Me.Col7.AutoSizeMode = DataGridViewAutoSizeColumnMode.None
            DataGridViewCellStyle8.Alignment = DataGridViewContentAlignment.MiddleCenter
            DataGridViewCellStyle8.BackColor = Drawing.Color.Silver
            DataGridViewCellStyle8.Font = New Drawing.Font("Microsoft Sans Serif", 8.25!, Drawing.FontStyle.Regular, Drawing.GraphicsUnit.Point, CType(0, Byte))
            DataGridViewCellStyle8.ForeColor = Drawing.Color.Black
            DataGridViewCellStyle8.NullValue = Nothing
            DataGridViewCellStyle8.SelectionBackColor = Drawing.Color.WhiteSmoke
            DataGridViewCellStyle8.SelectionForeColor = Drawing.Color.Black
            Me.Col7.DefaultCellStyle = DataGridViewCellStyle8
            Me.Col7.DividerWidth = 1
            Me.Col7.Frozen = True
            Me.Col7.HeaderText = " Steps"
            Me.Col7.Name = "Col7"
            Me.Col7.Resizable = DataGridViewTriState.[False]
            Me.Col7.SortMode = DataGridViewColumnSortMode.NotSortable
            Me.Col7.Width = 50
            '
            'Col8
            '
            Me.Col8.AutoSizeMode = DataGridViewAutoSizeColumnMode.None
            DataGridViewCellStyle9.Alignment = DataGridViewContentAlignment.MiddleCenter
            DataGridViewCellStyle9.BackColor = Drawing.Color.SkyBlue
            DataGridViewCellStyle9.Font = New Drawing.Font("Microsoft Sans Serif", 8.25!, Drawing.FontStyle.Regular, Drawing.GraphicsUnit.Point, CType(0, Byte))
            DataGridViewCellStyle9.ForeColor = Drawing.Color.Black
            DataGridViewCellStyle9.NullValue = Nothing
            DataGridViewCellStyle9.SelectionBackColor = Drawing.Color.AliceBlue
            DataGridViewCellStyle9.SelectionForeColor = Drawing.Color.Black
            Me.Col8.DefaultCellStyle = DataGridViewCellStyle9
            Me.Col8.DividerWidth = 1
            Me.Col8.Frozen = True
            Me.Col8.HeaderText = " -1=nil"
            Me.Col8.Name = "Col8"
            Me.Col8.Resizable = DataGridViewTriState.[False]
            Me.Col8.SortMode = DataGridViewColumnSortMode.NotSortable
            Me.Col8.Width = 50
            '
            'lblData
            '
            Me.lblData.BackColor = Drawing.Color.WhiteSmoke
            Me.lblData.BorderStyle = BorderStyle.FixedSingle
            Me.lblData.CausesValidation = False
            Me.lblData.Location = New Drawing.Point(175, 52)
            Me.lblData.Name = "lblData"
            Me.lblData.Size = New Drawing.Size(102, 20)
            Me.lblData.TabIndex = 0
            Me.lblData.Text = "           Data                "
            Me.lblData.TextAlign = Drawing.ContentAlignment.MiddleCenter
            '
            'lblGraph
            '
            Me.lblGraph.BorderStyle = BorderStyle.FixedSingle
            Me.lblGraph.CausesValidation = False
            Me.lblGraph.Location = New Drawing.Point(287, 52)
            Me.lblGraph.Name = "lblGraph"
            Me.lblGraph.Size = New Drawing.Size(271, 20)
            Me.lblGraph.TabIndex = 0
            Me.lblGraph.Text = "                         Graph                         "
            Me.lblGraph.TextAlign = Drawing.ContentAlignment.MiddleCenter
            '
            'DataGridView1
            '
            Me.DataGridView1.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize
            Me.DataGridView1.Location = New Drawing.Point(227, 63)
            Me.DataGridView1.Name = "DataGridView1"
            Me.DataGridView1.Size = New Drawing.Size(240, 150)
            Me.DataGridView1.TabIndex = 3
            '
            'frmChangeScale
            '
            Me.AutoSize = True
            Me.BackColor = Drawing.Color.WhiteSmoke
            Me.ClientSize = New Drawing.Size(584, 354)
            Me.Controls.Add(Me.DataGridView1)
            Me.Controls.Add(Me.lblGraph)
            Me.Controls.Add(Me.lblData)
            Me.Controls.Add(Me.dgvChangeScale)
            Me.Controls.Add(Me.cmdDone)
            Me.ForeColor = Drawing.Color.Black
            Me.Name = "frmChangeScale"
            Me.Text = "AffinityN - Select Graph Scales"
            CType(Me.dgvChangeScale, ISupportInitialize).EndInit()
            CType(Me.DataGridView1, ISupportInitialize).EndInit()
            Me.ResumeLayout(False)
    
        End Sub
    
    Finding the COM component:
    In regedit, I see HKEY_CLASSES_ROOT, but not it,s subdir \CLSID, so I will have to do some reading,
     as I have not used regedit much.
    
    Further steps:
    This is a middle sized translation, about 86 MB, so fixing all the warnings is not possible. 
    Many warnings I do not agree to, such as reusing variables, as it would lead to obscure code.
    
    Regards 
    David.


    David W. Macpherson

    Tuesday, April 10, 2012 1:47 AM
  • It isn't clear what exactly your issue is:

    Are you saying that the designer code 'changing' is a problem? This shouldn't be an issue as the designer will modify the designer code as appropriate for the controls: if it adds or removes qualified names, it still shouldn't be an issue.

    Are you changing the designer file yourself? If so, then you should avoid it: the designer code gets recreated by the IDE so any changes will need overwriting.

    Is the true issue the fact that events fire while the form is being created, which subsequently causes errors in the code for the event handlers? If so, then simply set a flag that the form has been initialized when the form has completed loading (end of the form load event) and perform a check in each handler routine to see if its set.

    Additionally, this is upgraded VB6 (or earlier?) code: the functionality will probably not be the same. Additionally, this may be a cause of the 'imports' issues that you have, as it really doesn't cause a problem with new projects. The huge number of warnings also suggests an upgraded project. essentially you have to go through each one and see what behavior has changed. A daunting task, of course, but the upgrade system is less than reliable (it does the best it can). If you don't address the warnings, you run a high likelihood that the application does not work the way it used to.

    As a few side notes:

    There's no need to dispose of the datagridview - it should be done automatically by the designer.

    There are On Error Goto statements and 'labels': something else to tidy up/eliminate.

    The Upgrade system sometimes doesn't put designer code in the designer.vb (e.g. InitializeComponent). Even though it's not where it is supposed to be, modifying that code will cause potential issues, and may be a source of the qualified name issues.


    Stephen J Whiteley

    Tuesday, April 10, 2012 1:29 PM
    Moderator
  • Something went wrong and it's not reproducable anymore.

    I suggest to recreate the Form. Backup your project before. Add a new Form and copy all controls from the Form you have to the new Form using the designer (copy&paste; do not move them because it removes the "handles" clause). Then copy the whole code (all but Initializecomponent) from the old file (not the designer file) to the new code file.

    Remove the old Form from the project and rename the new to the old name.

    Then enable Option Strict On.


    Armin

    Tuesday, April 10, 2012 2:29 PM
  • Rudy,( & Patrice)

    No, I am not using any tools such as FxCop.

    AffinityN is the file directory of the project. Affinity is the name of the project.

    I should have said "When I delete the imports files from frmChangeScale.designer.vb, I get an error".

    I have not changed any designer statements except as an error suggestion of the designer. Except in some sub InitializeComponent code, which appears at the end of the form.vb, I have had to enclose the sub with isinitializing = true, isinitializing = false statements, even though it is wiped out during a change in the designer. I have traced this to those forms which use DataGridView_CellValueChanged event, and textbox_TextChanged event, which must have the isinitializing statements in my first post of April 8, inserted in the designer code, even though they are wiped out during a designer change, requiring replacement. Although the form_load has these statements, sub initializeComponent runs first. The CellValuesChanged and TextChanged subs also must have a leading statement requiring a sub exit if the initializing flag is set, similar to code inserted by the MS VB6 to VB.net translator for comboBox SelectedIndexChanged events.

    Thank you for your interest.

    David.

     


    David W. Macpherson

    Wednesday, April 11, 2012 2:13 AM
  • Stephen,

    Thank you for your interest. See my reply to Rudy today April 11 (in Australia).

    Referring to your paragraphs:

    Para 1 & 2:

    My problem is the number of errors requiring designer-recommended alterations when the designer is altered and regenerated. Secondly, the fact that sub initializeComponent can run before my form_load is run, requires an isInitializing flag to be set in sub initializeComponent to prevent events firing, even though it will have to be replaced after designer regeneration. In these cases, the sub is at the end of the form.vb file.

    Para 3:

    If you look at the reply to Rudy, you will see that I use the necessary booleans in the form_load and in each handler routine.

    Para 4:

    Yes it is an upgrade of an in-use VB6 program. The different functionality noted by the upgrade program has been complied with. I have only given those warnings applicable to the designer, but many warnings I do not agree with, as they would lead to obscure code. The program as is now runs in debug without complaint.

    Paras 5 & 6:

    Datagridview is disposed because the warnings said so. Likewise it is also warning me to dispose of brushes and pens, fornt and formats. In the end, I put all these in a formclosing event.

    Note the dispose warnings for the designer,CA1063 in my post of april 9!

    Para 7:

    The unstructured On error goto statements are preferred by ex VB programmers, even though you have to insert those dreaded line numbers as labels, because it enables you to locate the line initiating the error. Do you have a similar facility with structured error statements? I have not found one when you do not where to insert the try.. statements.

    Last Para:

    What are the potential issues once you have modified sub InitializeComponent with the isinitializing =true/=false flag (only)? I have been running in debug for a considerable time without problems.

    Regards,

    David.


    David W. Macpherson

    Wednesday, April 11, 2012 4:08 AM
  • Patrice,

    re your advice on looking in RegEdit to finding the COM component giving the warning, RegEdit search gives the following:

    Name                                   Type        Value

    red list symbol (Default)        REG_SZ   972ABB3F-09C2-11D5-898E-0050DA7509CB

    How I find where this warning comes from and get rid of the warning, as no file, line or column is shown on the Error List warning?

    Regards,

    David 


    David W. Macpherson

    Wednesday, April 11, 2012 7:35 AM
  • Regarding Form_Load and initializing:

    Initialization runs first; when the Form_Load even runs, all the controls have been placed and the possibility of cascading events is likely. That is, evens will fire before Form_Load.

    What you need to do to combat this is to change your flagging mechanism. Use an 'Initialized' flag, set it true at the end of Form_Load. In your events, if it is false, then exit the event handler. This way allows you to leave all the designer code alone, and ignore the InitializeComponent routine.

    Note that ordinarily the InitializeComponent is in the .designer.vb; a file which it is not necessary to touch. Because you have an upgraded project, everything sounds like a mess of code. It will always be a potential issue if you do anything to the form layout; it may be quite frustrating. The designer methods (including InitializeComponent) can be completely reconstructed, removing any code you may add, when the form layout is changed. Long and short of it, don't do anything to these methods, let the IDE do its thing with them.

    Regarding Disposition:

    The DataGridView should not need disposing because it is added to the components collection of the form. The components are automatically disposed when required. Objects you create yourself do not automatically get added. You need to dispose those manually. Typically, when designing a form, any component you drop on a form automatically is added to the components collection so requires no additional work on your part. The 'designer' file contains all the code to declare and create the object, add it to the container, and set all the appropriate properties that you may change in the designer (the latter is where cascading events can get fired prior to the Form_Load event handler).

    On error Goto:

    I will disagree with the issue that they are a 'preferred' method of old-school VB programmers - they were the only method and were a poor mans form of error handling. With structured error handling there is a lot more versatility; its just that we didn't have it way back when (I've been programming VB since VB4). It is a paradigm shift to be true, and also your code will most likely need to be streamlined and restructured to take advantage of the better error handling techniques.

    This latter point is where the problem really lies - your upgrade project is like buying a new car but keeping the old engine, wiring, seats, radio, wheels, furry dice. I know that's not what you want to hear, but having been there, it is very frustrating trying to make an old app work.

    Can you recreate the form from scratch and copy the appropriate code to the correct handlers? I think this is going to e the easiest way, rather than combating issues each time a minor change to the layout is made.


    Stephen J Whiteley

    Wednesday, April 11, 2012 12:01 PM
    Moderator
  • It uses Protected OverLoads, not Protected Overrides.

    So it seems definitively not to the expected generated code. Could it be something that was created using an ealier version and upgraded to VS 2010 ? Or have you changed this earlier ? Generated code should never be updated.

    What if you disable code analysis to first make sure your code works as expected without being overwhelmed with those warnings. Then you can enable it at a later time when you have some time at your disposal to fix these issues.

    For example to remove CA1063, you'll have  to change "Protected Overloads" to "Protected Overrides" for Dispose methods...

    This is a middle sized "translation". Translation from what to what ? Have you used some code source translator to translate this code ? Please clairy if yhis code were ONLY created by the VS 2010 designer (or this is a port from an earlier VS version ?)


    Please always mark whatever response solved your issue so that the thread is properly marked as "Answered".

    • Marked as answer by David MacP Thursday, April 12, 2012 12:00 PM
    Wednesday, April 11, 2012 12:12 PM
  • So under HKEY_CLASSES_ROOT you have a CLSID branch in which you should likely find this ID. Then try to see if you have a InProcServer32 an/or a ProgId key. It should respectively allow to understand which DLL and class name it is...

    Or just look at References in your project to see which COM component is referenced and see if it is really needed ?


    Please always mark whatever response solved your issue so that the thread is properly marked as "Answered".

    Wednesday, April 11, 2012 12:18 PM
  • I believe that 2010 does NOT have an upgrade wizard, but both 2005 and 2008 did (I haven't had any real success with the VB6 upgrade tool, and haven't performed an upgrade in years, so could be wrong). So it is possibly this is an upgrade of an upgrade. Additionally, 2002/2003 did not have separate designer.vb files, lumping all the designer code in a single VB file.


    Stephen J Whiteley

    Wednesday, April 11, 2012 1:54 PM
    Moderator
  • Stephen,

    InitializeComponent:

    Using 'if initializing = true then exit sub' before comboboxes which may fire during form load, came from the VB6 to VB.net 2008 translator.

    I have done what you suggested,slightly changed, to 'if blnDataenterLoaded = false then exit sub' etc, and it works fine.

    I have replied to Patrice on the origins of the translation, and made the comment that most forms have been created with the 2010 toolbox, because I lost the forms and did not then know to get them back.

    Getting the On Line help ammended:

    I hope you can persuade your editorial friends at MS to give more useful information in Help, as the information, although voluminous, teaches nothing about the sorts of problems I am interested in. Even the examples do not give a complete sample of multiple editboxes or an unbound DataGridView sample for data entry. Likewise for drawing scatter graphs with multiple ordinate scales drawn in an engineering manner, not in the Excel manner.

    The reply to Patrice on the top subject is reproduced here, as It disappeared into the ether and did not come back after submitting:

    Patrice,

    Yes, changing the generated designer code from 'Overloads' to 'Overrides'  did not produce an objection, and it works, removing all CA1063 warnings.

    I have tried this  before, but the designer flagged an error, so something must have changed. If the error had not been flagged, I would have made the change. I have looked back on the translator (see below) files in VB.net 2008, and the designer had 'Overloads'

    Your last paragraph:

    The program used the VB6 to vb.net 2008 translator available only on VB.net 2008. Modifications as necessary were made when running vb.net 2010 and VS Ultimate. I made mistakes with most of the forms, so most were recreated using 2010 toolbox.

    Thanks for the assistance.


    David W. Macpherson

    Thursday, April 12, 2012 12:27 PM