المساعد الشخصي الرقمي

مشاهدة النسخة كاملة : ListView subitems problem... finds column but throws error.. DRIVING ME NUTS!



C# Programming
11-19-2009, 01:04 AM
I cannot figure this out! It is driving me nuts!

Ok so I can do a IndexOfKey and get the index (which in my case is 24), but when I try to get the text it gives an error:


int index = 0;
index = lstImport.Columns.IndexOfKey("Category");

MessageBox.Show(index.ToString()); // THIS SHOWS 24

if (index == -1) cmd.Parameters.AddWithValue("@Category", "");
else cmd.Parameters.AddWithValue("@Category", lstImport.Items[i].SubItems[index].Text); // THIS ERRORS


ERROR:

System.ArgumentOutOfRangeException was unhandled
Message="InvalidArgument=Value of '24' is not valid for 'index'.\r\nParameter name: index"
Source="System.Windows.Forms"
ParamName="index"
StackTrace:
at System.Windows.Forms.ListViewItem.ListViewSubItemCollection.get_Item(Int32 index)
at Grant_Inventory_Import.frmMain.ImportData() in C:\Users\jdixon\Documents\Visual Studio 2008\Projects\Grant Inventory Import\Grant Inventory Import\frmMain.cs:line 560
at Grant_Inventory_Import.frmMain.btnImport_Click(Object sender, EventArgs e) in C:\Users\jdixon\Documents\Visual Studio 2008\Projects\Grant Inventory Import\Grant Inventory Import\frmMain.cs:line 221
at System.Windows.Forms.Control.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ButtonBase.WndProc(Message& m)
at System.Windows.Forms.Button.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNative********OnMessage(Message& m)
at System.Windows.Forms.Control.ControlNative********WndProc(Message& m)
at System.Windows.Forms.Native********DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoCompo nentManager.FPushMessageLoop(Int32 dwComponentID, Int32 reason, Int32 pvLoopData)
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(Form mainForm)
at Grant_Inventory_Import.Program.Main() in C:\Users\jdixon\Documents\Visual Studio 2008\Projects\Grant Inventory Import\Grant Inventory Import\Program.cs:line 18
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: