Click here to Skip to main content
15,887,214 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
The following piece of code was working fine with "Visual Studio 2005 Tools For Office Runtime" and VS 2008.. Office 2003 was targeted for this.


static public void ResizeAllNamedRanges(
                           Tools.WorksheetBase wksht,
                           int iResizeRows,
                           int iResizeCols,
                           bool bFillDown )
                     {
                           Debug.Assert( wksht != null );
 
 
                           for ( int i = 0; i < wksht.Controls.Count; i++ )
                           {
 
                                  if ( ( ( object )( wksht.Controls[ i ] ) ).GetType( ) ==
                                         typeof( Tools.NamedRange ) )
                                  {
                                         ResizeNamedRange(
                                                ( Tools.NamedRange )wksht.Controls[ i ],
                                                iResizeRows, iResizeCols
                                         );
 
                                         if ( bFillDown )
                                         {
                                                ( ( Tools.NamedRange )wksht.Controls[ i ] ).FillDown( );
                                         }
                                  }
                           }
                     }


But now, when I have migrated to VS 2010 targeting Office 2010, this code does not work. It Builds fine.. but the issue is that the following condition is not getting satisfied,although there are named ranges in worksheet. This condition was getting satisfied before migration.

if ( ( ( object )( wksht.Controls[ i ] ) ).GetType( ) == typeof( Tools.NamedRange ) )



Also when I try a quick watch on wksht.Controls[i]. I get the following error:
"Cannot apply indexing with [] to an expression of type Microsoft.Office.Tools.Excel.ControlCollection".

Can anyone please help? Is it a migration issue? Am I missing out on something?

Thanks.
Posted
Updated 3-Jan-12 3:49am
v3

1 solution

Are you not casting the worksheet control to type object in the code above?

resulting in (simplified) if (System.object == Tools.NamedRange)


Should this not be written;

if ( wksht.Controls[ i ].GetType( ) == typeof( Tools.NamedRange ) )
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900