ListView-Problem in conjunction with COM 
Author Message
 ListView-Problem in conjunction with COM

Hello NG!

I have a problem in a C# Windows application: i want to use the COM-Version
of the ListView-control there, but i can't get the Add-method working. If I
try the following line:

lvwLogins.ListItems.Add(ref dummy,ref dummy,ref (object) strItem,ref
dummy,ref dummy);

where "dummy" is of type "System.Object", the compiler says:

"A ref or out argument must be an lvalue"

If I cast the Variable "strItem" to "System.Object" before and use it in the
call then, just like this:

     objItem = (object) strItem;
     lvwLogins.ListItems.Add(ref dummy,ref dummy,ref objItem,ref dummy,ref
dummy);

...compiling succeeds, but at runtime it stops at the Add-method and throws
an exception:

'System.Runtime.InteropServices.COMException' occurred in CSCableTool.exe
Additional information: Typen unvertr?glich

(Typen unvertr?glich = Type mismatch)

Now, what should I do? In VB.NET it works without any problems to specifiy a
string or even a ADODB.Field. So there must be a solution in C# too.

It'd be great if there's someone who can help me!

Thanx in advance and greetings from Bregenz (AT) :)

Michael



Mon, 18 Oct 2004 17:30:44 GMT  
 ListView-Problem in conjunction with COM
Hello Michael,

I think the problem is that you define the strItem as a string. The
parameter is defined as a "ref object", which means it may be set with an
object. The compiler can not ensure the object set back to the strItem can
be cast to a string, hence it will report an error.

You can use the code below:

object Index = 1;
object Key =  "Key";
object Item = "Test";
object dummy = null;
lvwLogins.ListItems.Add(ref Index, ref Key, ref Item, ref dummy, ref dummy);

However, I don't think it will work if set the Index and Key parameters to
null.

I hope it helps.

Best regards,

Lion Shi, MCSE, MCSD
Microsoft Support Engineer

This posting is provided "AS IS" with no warranties, and confers no rights.
You assume all risk for your use.  2001 Microsoft Corporation. All rights
reserved.
--------------------

    Newsgroups: microsoft.public.dotnet.languages.csharp
    Subject: ListView-Problem in conjunction with COM
    Date: Thu, 2 May 2002 11:30:44 +0200
    Organization: Customer of Energis Squared
    Lines: 38

    NNTP-Posting-Host: 194-208-020-131.tele.net
    X-Trace: newsreaderg1.core.theplanet.net 1020331760 12475
194.208.20.131 (2 May 2002 09:29:20 GMT)
    NNTP-Posting-Date: 2 May 2002 09:29:20 GMT

    X-Priority: 3
    X-MSMail-Priority: Normal
    X-Newsreader: Microsoft Outlook Express 6.00.2600.0000
    X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2600.0000
    Path:
cpmsftngxa08!cpmsftngxa07!tkmsftngp01!newsfeed00.sul.t-online.de!t-online.de
!newsfeed.icl.net!newspeer.clara.net!news.clara.net!diablo.theplanet.net!dia
blo.theplanet.net!news.theplanet.net!not-for-mail
    Xref: cpmsftngxa08 microsoft.public.dotnet.languages.csharp:58087
    X-Tomcat-NG: microsoft.public.dotnet.languages.csharp

    Hello NG!

    I have a problem in a C# Windows application: i want to use the
COM-Version
    of the ListView-control there, but i can't get the Add-method working.
If I
    try the following line:

    lvwLogins.ListItems.Add(ref dummy,ref dummy,ref (object) strItem,ref
    dummy,ref dummy);

    where "dummy" is of type "System.Object", the compiler says:

    "A ref or out argument must be an lvalue"

    If I cast the Variable "strItem" to "System.Object" before and use it
in the
    call then, just like this:

         objItem = (object) strItem;
         lvwLogins.ListItems.Add(ref dummy,ref dummy,ref objItem,ref
dummy,ref
    dummy);

    ...compiling succeeds, but at runtime it stops at the Add-method and
throws
    an exception:

    'System.Runtime.InteropServices.COMException' occurred in
CSCableTool.exe
    Additional information: Typen unvertr?glich

    (Typen unvertr?glich = Type mismatch)

    Now, what should I do? In VB.NET it works without any problems to
specifiy a
    string or even a ADODB.Field. So there must be a solution in C# too.

    It'd be great if there's someone who can help me!

    Thanx in advance and greetings from Bregenz (AT) :)

    Michael



Fri, 22 Oct 2004 17:24:53 GMT  
 ListView-Problem in conjunction with COM
Hi!

Everyone who's interested in the problem's solution should visit

http://www.developersdex.com/csharp/message.asp?r=1659065&p=1111

Greetings...

Michael

Quote:
> Hello NG!

> I have a problem in a C# Windows application: i want to use the
COM-Version
> of the ListView-control there, but i can't get the Add-method working. If
I
> try the following line:

> lvwLogins.ListItems.Add(ref dummy,ref dummy,ref (object) strItem,ref
> dummy,ref dummy);

> where "dummy" is of type "System.Object", the compiler says:

> "A ref or out argument must be an lvalue"

> If I cast the Variable "strItem" to "System.Object" before and use it in
the
> call then, just like this:

>      objItem = (object) strItem;
>      lvwLogins.ListItems.Add(ref dummy,ref dummy,ref objItem,ref dummy,ref
> dummy);

> ...compiling succeeds, but at runtime it stops at the Add-method and
throws
> an exception:

> 'System.Runtime.InteropServices.COMException' occurred in CSCableTool.exe
> Additional information: Typen unvertr?glich

> (Typen unvertr?glich = Type mismatch)

> Now, what should I do? In VB.NET it works without any problems to specifiy
a
> string or even a ADODB.Field. So there must be a solution in C# too.

> It'd be great if there's someone who can help me!

> Thanx in advance and greetings from Bregenz (AT) :)

> Michael



Tue, 26 Oct 2004 17:35:36 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. CMap in conjunction with CString has problem

2. C++ code, problem using PlaySound API in conjunction with SND_RESOURCE

3. Redirecting standard I/O in conjunction with AllocConsole

4. Template in conjunction with IMPLEMENT_SERIAL

5. Problem with COM object creation with a COM service

6. Problem calling VB COM dll from VC++ multithreaded COM EXE client

7. COM DLL TO COM EXE problem!

8. Problem with scripting context when using VB com object inside VC com object

9. problems passing ADO Recordset from VB-COM client to VC-COM-Server dll

10. Problem redrawing sort indicator in ListView

11. ListView Control Problem

12. Windows Form ListView problem

 

 
Powered by phpBB® Forum Software