Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

Has anyone come accross this ListView error before and know how to remedy it:

 

A first chance exception of type 'System.Reflection.AmbiguousMatchException' occurred in microsoft.visualbasic.dll

 

Additional information: No accessible overloaded 'ListViewSubItemCollection.Add' can be called without a narrowing conversion. (VB.NET)

 

It seems to occur if I add a second subitem to my ListView.

Its ok with 1 item and subitem.

Posted

I am using an Outlook COM library called CDO.dll to display Inbox messages. Turning on Option Strict seems to indicate I have lots of late binding. I have read up on this and being new to VB.NET I have no idea how to use the better suggested way of early binding. My code anyway that is giving me problems, which partially works with Option Explicit On is:

 

Dim colMessages As MAPI.Messages

Dim objMessage As MAPI.Message

Dim lstStuff As New ListViewItem

Dim count As Integer

 

 

With ListView1.Items

For Each objMessage In gobjSession.Inbox.Messages

 

lstStuff = .Add(objMessage.Size)

 

With lstStuff

.SubItems.Add(objMessage.Subject)

.SubItems.Add(objMessage.TimeReceived) ' error occurs if add this line

 

End With

Next

 

End With

End Sub

 

cheers!

  • *Gurus*
Posted

The Add method has three overloads, once accepting a string, one a previously instantiated listviewsubitem and one accepting string plus color and font information. By the looks of it, in that code you're trying to pass an integer, a string and a date/time field in three instances.

 

Hopefully that shows you the problem - those need converting to string before they're passed. Converting to string in .NET is easy, in most cases you can use the .ToString() method of whatever you want to convert. So instead of trying to pass objMessage.Size, pass objMessage.Size.ToString() etc.

MVP, Visual Developer - .NET

 

Now you see why evil will always triumph - because good is dumb.

 

My free .NET Windows Forms Controls and Articles

Posted

Cheers Divil, Worked a treat, Brilliant!!

Would it be possible to ask one more favour?

Do you happen to know how I can retrieve the contents of the items; specifically the first column, depending on the one the user clicks on and other columns if possible.

 

I have tried using the SelectedIndexChanged event and a call to the "listitems .Text" property but it just returns the last items text in the first column, no matter which item you click on. I know that some kind of index method is needed but cannot get my head round how it operates and havn't found any examples on here or anywhere else or in my books.

 

Cheers!

Posted
cheers for that. In the end I used the mouse up control and a getter to obtain the field being clicked in the ListView and the .text property as you mentioned to get the contence of the field. Found the method on an example from the MSDN section of Microsofts site.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...