locked
Unable to access controls on a form RRS feed

  • Question

  •  Hello,
    I was having problems with a program I'm making in VB using VB Express and have resolved most of thenm except one. when I took out the code in the form.designer.vb module, and pasted it back, it now sees the control names that I've been using but when I go to add a control such as a listbox and call it by name, it gives me the following error:

    "There is already a component named 'lstMusic'.  Components must have unique names, and names must be case-insensitive.  A name also cannot conflict with the name of any component in an inherited class".

    I really don't want to delete the form and start over. Is there anyway to let the form see the controls again.

    Thanks for all your help in advance,

    PCRider
    Thursday, July 3, 2008 4:08 PM

Answers

  • PCRider said:
    when I took out the code in the form.designer.vb module, and pasted it back, it now sees the control names that I've been using but when I go to add a control such as a listbox and call it by name, it gives me the following error:

    "There is already a component named 'lstMusic'.  Components must have unique names, and names must be case-insensitive.  A name also cannot conflict with the name of any component in an inherited class".

    I really don't want to delete the form and start over. Is there anyway to let the form see the controls again.

    Hi PCRider,

    When you drag&drop a ListBox control (named lstMusic) to Form1, related code to lstMusic object will be generated automatically. The Form1.Designer.vb code structure is like this, I hightlighten them with four parts. Please double check they are completed in your form.designer.vb file if you want to restore original control.
    <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.lstMusic = New System.Windows.Forms.ListBox  'Part 2: Instantialize the object
            Me.SuspendLayout()  
            '  
            'lstMusic           'Part 3: Set UI settings for the object
            '  
            Me.lstMusic.FormattingEnabled = True 
            Me.lstMusic.Location = New System.Drawing.Point(67, 80)  
            Me.lstMusic.Name = "lstMusic" 
            Me.lstMusic.Size = New System.Drawing.Size(120, 95)  
            Me.lstMusic.TabIndex = 0  
            '  
            'Form1  
            '  
            Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 13.0!)  
            Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font  
            Me.ClientSize = New System.Drawing.Size(292, 266)  
            Me.Controls.Add(Me.lstMusic)  'Part 4: Add the object to Form
            Me.Name = "Form1" 
            Me.Text = "Form1" 
            Me.ResumeLayout(False)  
     
        End Sub 
     
        Friend WithEvents lstMusic As System.Windows.Forms.ListBox 'Part 1: Declare one object
     
    End Class 


    "There is already a component named 'lstMusic'.  Components must have unique names, and names must be case-insensitive.  A name also cannot conflict with the name of any component in an inherited class".
    -> The error message indicate there is already a component named 'lstMusic' created on your Form class. You either use other name or remove the original object.


    Best regards,
    Martin Xie
    Thursday, July 10, 2008 9:01 AM