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.