Why don't partial class files group?


B

Brett Romero

I have a .NET 1.1 form that was migrated into 2.0. Its class file is
in form1.cs. I've created another "code" file named form1.designer.cs
and with this code:

partial class form1

in the same namespace as form1. form1.cs declares its class as

public partial class form1: Form

However, the designer file icon in solution explorer is labeled as c#
in green and not grouped under form1.cs. partial classes I've seen
created in the VS 2005 are always group under the root partial.

Is there something additional I need to do for this to happen?

Thanks,
Brett
 
Ad

Advertisements

D

Derrick Coetzee [MSFT]

Brett said:
However, the designer file icon in solution explorer is labeled as c#
in green and not grouped under form1.cs. partial classes I've seen
created in the VS 2005 are always group under the root partial.

Is there something additional I need to do for this to happen?

Hi Brett. The grouping of these files is not due to their containing parts
of the same class, but is rather something done by the designer wizard. If
you didn't run the wizard to create them in the new project, they won't be
grouped, although they will compile fine. The only way I know to deal with
this is to first create an identically named form using the wizard, then
close the project and copy the old source files over the generated files. I
hope this helps.
 
B

Brett Romero

So the only way is to create a form? And from there you can't add any
new files to the same group (since the wizard only creates two partial
classes, including the master)?

Thanks,
brettr
 
D

Derrick Coetzee [MSFT]

Brett said:
So the only way is to create a form? And from there you can't add any
new files to the same group (since the wizard only creates two partial
classes, including the master)?

Well, not from the GUI as far as I know, but if you're willing to go under
the hood there is a way to add files to groups like this. Open up the
project (.csproj) file in a text editor, and find the XML element that looks
like this:

<Compile Include="FileYouWantInGroup.cs" />

Change it to this:

<Compile Include="FileYouWantInGroup.cs">
<DependentUpon>FileWhoseGroupItGoesIn.cs</DependentUpon>
</Compile>

This should do what you want (I'm not sure if it has any other effects).
Normally, however, this is only used for files that are generated from or
otherwise dependent on the "root" file, as the name "DependentUpon" above
suggests. I hope this helps.
 
Ad

Advertisements


Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top