error with Insert a new row in OWC spreadsheet

R

Rich

I have the coding as below to insert a new row in OWC spreadsheet.
OWC11.Range rng = (OWC11.Range) spreadsheet.Cells[1,1];
rng.EntireRow.Insert(OWC11.XlInsertShiftDirection.xlShiftDown);
....
but always got below error:
The best overloaded method match for 'OWC11._Range.Insert(ref object)'
has some invalid arguments
Argument '1': cannot convert from 'OWC11.XlInsertShiftDirection' to
'ref object'

Can anyone tell me what's wrong with this coding?

Thanks in advance.
 
A

Alvin Bruney

You are passing an enumeration to an object with a ref object parameter.
That simply is not possible to accomplish. Re-examine the method signature
to be certain if this is the required argument. If it is, convert the
enumerator to an object and add the ref tag.

Essentially, your failure boils down to something like this:
//signature
insert(ref 1)
{
}

since one is a constant, it can't be passed as a ref arg. To workaround, you
can do this
object one = 1;
insert(ref one)

this subtle difference will keep the compiler quite.

--

________________________
Warm regards,
Alvin Bruney [MVP ASP.NET]

[Shameless Author plug]
The O.W.C. Black Book with .NET
www.lulu.com/owc, Amazon
Professional VSTO.NET - Wrox/Wiley 2006
 

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