views:

561

answers:

5

In Visual Studio, two files are created when you create a new Windows Form in your solution (e.g. if you create MyForm.cs, MyForm.Designer.cs and MyForm.resx are also created). These second two files are displayed as a subtree in the Solution Explorer.

Is there any way to add files to the sub-tree or group for a Windows Form class?

+5  A: 

You need to edit the csproj directly. There is a DependentUpon tag that you have to add as a child tag of the file you want to place under MyForm.cs.

Example:

<Compile Include="MyForm.MyCoolSubFile.cs">
  <DependentUpon>MyForm.cs</DependentUpon>
</Compile>
Jeff Yates
+9  A: 

Open .csproj in edit mode, look for the file you want to be under another one, and add the DependentUpon element, like this:

<Compile Include="AlertDialog.xaml.cs">
  <DependentUpon>AlertDialog.xaml</DependentUpon>
</Compile>
Santiago Palladino
+3  A: 

Yes, but it's a bit of a hassle - basically you need to edit the project file by hand.

Here's an example from a project that Marc Gravell and I both work on:

<Compile Include="Linq\Extensions\DataProducerExt.cs" />
<Compile Include="Linq\Extensions\DataProducerExt.SingleReturn.cs">
  <DependentUpon>DataProducerExt.cs</DependentUpon>
</Compile>
<Compile Include="Linq\Extensions\DataProducerExt.Grouping.cs">
  <DependentUpon>DataProducerExt.cs</DependentUpon>
</Compile>
<Compile Include="Linq\Extensions\DataProducerExt.Pipeline.cs">
  <DependentUpon>DataProducerExt.cs</DependentUpon>
</Compile>
<Compile Include="Linq\Extensions\DataProducerExt.Conversion.cs">
  <DependentUpon>DataProducerExt.cs</DependentUpon>
</Compile>
<Compile Include="Linq\Extensions\DataProducerExt.Math.cs">
  <DependentUpon>DataProducerExt.cs</DependentUpon>
</Compile>

Note the "DependentUpon" element in each of the dependencies. This displays appropriately in VS, with DataProducerExt.cs as the parent.

Jon Skeet
+1  A: 

Currently there's at least one Visual Studio Add-In that supports this from within Visual Studio itself - see http://visualstudiogallery.com/ExtensionDetails.aspx?ExtensionID=e93945c9-96e8-4a0d-bcc3-bd40bf799773

AndrejT
+1  A: 

I've created a Visual Studio adding that does it (and more). It works with VS 2008 and 2010 and you can check it out here: http://mokosh.co.uk/vscommands

jarek