masj78 Posted August 28, 2003 Posted August 28, 2003 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. Quote
*Gurus* divil Posted August 28, 2003 *Gurus* Posted August 28, 2003 Can you post the code where this error occurs? Try turning on Option Strict, it will force you to be explicit when it comes to converting types. You should always have it on, and it helps prevent errors like this. Quote MVP, Visual Developer - .NET Now you see why evil will always triumph - because good is dumb. My free .NET Windows Forms Controls and Articles
masj78 Posted August 28, 2003 Author Posted August 28, 2003 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! Quote
*Gurus* divil Posted August 29, 2003 *Gurus* Posted August 29, 2003 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. Quote MVP, Visual Developer - .NET Now you see why evil will always triumph - because good is dumb. My free .NET Windows Forms Controls and Articles
masj78 Posted August 29, 2003 Author Posted August 29, 2003 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! Quote
*Gurus* divil Posted August 31, 2003 *Gurus* Posted August 31, 2003 myListView.SelectedItems(0).SubItems(1).Text Quote MVP, Visual Developer - .NET Now you see why evil will always triumph - because good is dumb. My free .NET Windows Forms Controls and Articles
masj78 Posted September 1, 2003 Author Posted September 1, 2003 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. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.