Search code examples
vb.netwinformsuser-controls

Cannot rename control to that of a control I deleted


I'm having problems with two UserControls in VB.Net. I'm using VS2012. The UserControl is a panel called DataDriver, which at runtime is created dynamically on a form. Within DataDriver there is a control which is an instance of another UserControl defined in the project called DataLink. DataLink allows the user to select a data source (effectively a named connection string). Both the UserControls are defined in the same project.

At one point within the last 24 hours, I opened DataDriver in design mode and it showed me the screen I often get that states: "To prevent possible data loss before loading the designer, the following errors must be resolved: " with an "Ignore and Continue" link on it, which I clicked. I'm not entirely sure why this appears, but it does.

Once I'd opened DataDriver I found that the UserControl DataLink had disappeared. I created a new instance of it and tried to rename it to its original name (ucDataLink) with the error:

Property value is not valid. There is already a component named 'ucDataLink'. 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've closed the project, been through the three components of the UserControl DataDriver (the designer, the resx and the code) and removed any references to ucDataLink, and still is continues to raise this error. I can potentially use a different name, but this is the name that makes sense and I'd like to know how to resolve it.

Extra info. The DataDriver control is only instantiated at runtime. The form it is created in has a public method that is called. The form sets up the dynamic controls as below, and then shows using me.ShowDialog().

moActionEdit = New DataDriver
moActionEdit.Globals = g
moActionEdit.ConnectionName = mcConnectionName
moActionEdit.left = 0
moActionEdit.Top = 0
moActionEdit.width = pnl.Width
moActionEdit.Height = pnl.Height
moActionEdit.Anchor = AnchorStyles.Top + AnchorStyles.Left + AnchorStyles.Right + AnchorStyles.Bottom
moActionEdit.Job = moJob
pnl.Controls.Add(moActionEdit)
moActionEdit.Visible = True
If Not moActionEdit.Init() Then
    moActionEdit.Visible = False
    Throw New DolphinException("Could not initialise data entry panel for this action type correctly.", True)
End If

How can I successfully rename my UserControl back to ucDataLink?


Solution

  • Occasionally when you delete a control, it doesn't get deleted in the .Designer file. This isn't a particularly safe thing to do, so be careful.

    In the Solution Explorer, click on the button to show all files.

    Then also in Solution Explorer, click on the Right Arrow next to the form.

    In the expanded list, you'll see a file that is something like Form1.Designer.vb

    I would strongly recommend making a copy of this file using Windows File Explorer before making any changes.

    Open this file and look for all the lines that contain the name of your deleted control and remove them. Save the file, and you should now be able to rename the new control to the same as the old one.