mastertorr
Programmer
Control: Microsoft ListView Control, Version 6.
ERROR:
System.InvalidCastException was unhandled
Message="Unable to cast COM object of type 'MSComctlLib.ListItemClass' to class type 'System.Windows.Forms.ListViewItem'. Instances of types that represent COM components cannot be cast to types that do not represent COM components; however they can be cast to interfaces as long as the underlying COM component supports QueryInterface calls for the IID of the interface."
Source="Project"
StackTrace:
at Project.frmStartup.LoadListView() in C:\Documents and Settings\Ennis\My Documents\Visual Studio 2008\Projects\Project\Project\frmStartup.vb:line 24
at Project.frmStartup.frmStartup_Load(Object sender, EventArgs e) in C:\Documents and Settings\Ennis\My Documents\Visual Studio 2008\Projects\Project\Project\frmStartup.vb:line 11
at System.EventHandler.Invoke(Object sender, EventArgs e)
at System.Windows.Forms.Form.OnLoad(EventArgs e)
at System.Windows.Forms.Form.SetVisibleCore(Boolean value)
at System.Windows.Forms.Control.set_Visible(Boolean value)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.Run(ApplicationContext context)
at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.OnRun()
at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.DoApplicationModel()
at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.Run(String[] commandLine)
at Project.My.MyApplication.Main(String[] Args) in 17d14f5c-a337-4978-8281-53493378c1071.vb:line 81
at System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)
at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
InnerException:
=====================================================
Code Being used:
For i = 1 To openrec.RecordCount
lstitem = AxListView1.ListItems.Add()
lstitem.Text = openrec.Fields("field1").Value
lstitem.SubItems(1) = openrec.Fields("field1").Value
lstitem.SubItems(2) = openrec.Fields("field2").Value
openrec.MoveNext()
Next
========================================================
Anyone know why I am getting this error? I am trying to load a listview with information from my database.
ERROR:
System.InvalidCastException was unhandled
Message="Unable to cast COM object of type 'MSComctlLib.ListItemClass' to class type 'System.Windows.Forms.ListViewItem'. Instances of types that represent COM components cannot be cast to types that do not represent COM components; however they can be cast to interfaces as long as the underlying COM component supports QueryInterface calls for the IID of the interface."
Source="Project"
StackTrace:
at Project.frmStartup.LoadListView() in C:\Documents and Settings\Ennis\My Documents\Visual Studio 2008\Projects\Project\Project\frmStartup.vb:line 24
at Project.frmStartup.frmStartup_Load(Object sender, EventArgs e) in C:\Documents and Settings\Ennis\My Documents\Visual Studio 2008\Projects\Project\Project\frmStartup.vb:line 11
at System.EventHandler.Invoke(Object sender, EventArgs e)
at System.Windows.Forms.Form.OnLoad(EventArgs e)
at System.Windows.Forms.Form.SetVisibleCore(Boolean value)
at System.Windows.Forms.Control.set_Visible(Boolean value)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.Run(ApplicationContext context)
at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.OnRun()
at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.DoApplicationModel()
at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.Run(String[] commandLine)
at Project.My.MyApplication.Main(String[] Args) in 17d14f5c-a337-4978-8281-53493378c1071.vb:line 81
at System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)
at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
InnerException:
=====================================================
Code Being used:
For i = 1 To openrec.RecordCount
lstitem = AxListView1.ListItems.Add()
lstitem.Text = openrec.Fields("field1").Value
lstitem.SubItems(1) = openrec.Fields("field1").Value
lstitem.SubItems(2) = openrec.Fields("field2").Value
openrec.MoveNext()
Next
========================================================
Anyone know why I am getting this error? I am trying to load a listview with information from my database.