本帖最后由 saybookcat 于 2011-08-01 12:47:34 编辑

解决方案 »

  1.   

    List<Analyst> => ObservableCollection<Analyst>
      

  2.   

    什么意思 ??
    把List<Analyst> 换成 ObservableCollection<Analyst>吗?
      

  3.   

    未处理 System.Reflection.TargetInvocationException
      Message=调用的目标发生了异常。
      Source=mscorlib
      StackTrace:
           在 System.RuntimeMethodHandle._InvokeMethodFast(Object target, Object[] arguments, SignatureStruct& sig, MethodAttributes methodAttributes, RuntimeTypeHandle typeOwner)
           在 System.RuntimeMethodHandle.InvokeMethodFast(Object target, Object[] arguments, Signature sig, MethodAttributes methodAttributes, RuntimeTypeHandle typeOwner)
           在 System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, Boolean skipVisibilityChecks)
           在 System.Delegate.DynamicInvokeImpl(Object[] args)
           在 System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Boolean isSingleParameter)
           在 System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Boolean isSingleParameter, Delegate catchHandler)
           在 System.Windows.Threading.Dispatcher.WrappedInvoke(Delegate callback, Object args, Boolean isSingleParameter, Delegate catchHandler)
           在 System.Windows.Threading.DispatcherOperation.InvokeImpl()
           在 System.Windows.Threading.DispatcherOperation.InvokeInSecurityContext(Object state)
           在 System.Threading.ExecutionContext.runTryCode(Object userData)
           在 System.Runtime.CompilerServices.RuntimeHelpers.ExecuteCodeWithGuaranteedCleanup(TryCode code, CleanupCode backoutCode, Object userData)
           在 System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)
           在 System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
           在 System.Windows.Threading.DispatcherOperation.Invoke()
           在 System.Windows.Threading.Dispatcher.ProcessQueue()
           在 System.Windows.Threading.Dispatcher.WndProcHook(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
           在 MS.Win32.HwndWrapper.WndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
           在 MS.Win32.HwndSubclass.DispatcherCallbackOperation(Object o)
           在 System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Boolean isSingleParameter)
           在 System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Boolean isSingleParameter, Delegate catchHandler)
           在 System.Windows.Threading.Dispatcher.WrappedInvoke(Delegate callback, Object args, Boolean isSingleParameter, Delegate catchHandler)
           在 System.Windows.Threading.Dispatcher.InvokeImpl(DispatcherPriority priority, TimeSpan timeout, Delegate method, Object args, Boolean isSingleParameter)
           在 System.Windows.Threading.Dispatcher.Invoke(DispatcherPriority priority, Delegate method, Object arg)
           在 MS.Win32.HwndSubclass.SubclassWndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam)
           在 MS.Win32.UnsafeNativeMethods.DispatchMessage(MSG& msg)
           在 System.Windows.Threading.Dispatcher.PushFrameImpl(DispatcherFrame frame)
           在 System.Windows.Threading.Dispatcher.PushFrame(DispatcherFrame frame)
           在 System.Windows.Threading.Dispatcher.Run()
           在 System.Windows.Application.RunDispatcher(Object ignore)
           在 System.Windows.Application.RunInternal(Window window)
           在 System.Windows.Application.Run(Window window)
           在 System.Windows.Application.Run()
           在 OIS.App.Main() 位置 C:\My Folder\projects\OIS\OIS\obj\Debug\App.g.cs:行号 0
           在 System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)
           在 System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
           在 Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
           在 System.Threading.ThreadHelper.ThreadStart_Context(Object state)
           在 System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
           在 System.Threading.ThreadHelper.ThreadStart()
      InnerException: System.InvalidOperationException
           Message=当 ItemsSource 正在使用时操作无效。改用 ItemsControl.ItemsSource 访问和修改元素。
           Source=PresentationFramework
           StackTrace:
                在 System.Windows.Controls.ItemCollection.CheckIsUsingInnerView()
                在 System.Windows.Controls.ItemCollection.Add(Object newItem)
                在 OIS.MainWindow.<>c__DisplayClassa.<ResponseAddAnalysis>b__5() 位置 C:\My Folder\projects\OIS\MainWindow.cs:行号 214
           InnerException: 修改了,还是出现同样的错误
    报错的位置还是tvMyAnalyst.Items.Add(item); 这一句 
      

  4.   

    采用其他的办法解决了没有直接对treeview控件进行操作。而是对treeview绑定的数据集进行操作再绑定 解决的