when we use filter in the ListView and call IsFiltered property of some item the exception "Index was out of range. Must be non-negative and less than the size of the collection.\r\nParameter name: index" is thrown (see the call stack below)
We would suggest to return an old code in the class ContainerListViewItemFilter like this:
public bool Belongs(object o)
{
ContainerListViewItem item = o as ContainerListViewItem;
if(item == null)
return false;
if (_columnIndex >= item.SubItems.Count)
return true;
string actual = item.SubItems[_columnIndex].Text.ToLower(CultureInfo.CurrentCulture);
if(actual.IndexOf(_string) != -1)
return true;
else
return false;
}
---------------------call stack-----------------------
at System.Collections.ArrayList.get_Item(Int32 index)
at DotNetLib.Windows.Forms.ContainerListViewSubItemCollection.get_Item(Int32 index) in C:\Work\Spik\DotNetLib\Source\Windows\DotNetLib.Windows.Forms\ContainerListViewSubItemCollection.cs:line 59
at DotNetLib.Windows.Forms.ContainerListViewItemFilter.Belongs(Object o) in C:\Work\Spik\DotNetLib\Source\Windows\DotNetLib.Windows.Forms\ContainerListViewComparer.cs:line 105
at DotNetLib.Windows.Forms.ContainerListViewItem.get_IsFiltered() in C:\Work\Spik\DotNetLib\Source\Windows\DotNetLib.Windows.Forms\ContainerListViewItem.cs:line 697
at DotNetLib.Windows.Forms.ContainerListViewItem.get_IsFiltered() in C:\Work\Spik\DotNetLib\Source\Windows\DotNetLib.Windows.Forms\ContainerListViewItem.cs:line 700
at Test2.Form1.btnFilter_Click(Object sender, EventArgs e) in C:\Work\Spik\DotNetLib\Samples\Windows\Test2\Form1.cs:line 81
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.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.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.IMsoComponentManager.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 Test2.Program.Main() in c:\Work\Spik\DotNetLib\Samples\Windows\Test2\Program.cs:line 17
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()