2011-12-30 33 views
5

Tengo una vista en árbol Estudiantes. Mis artículos en treeview son nombres de estudiantes en una clase. Al seleccionar un elemento en TreeView, los datos en mi DataGrid 'StudentDetails' deberían cambiar. My DataGrid tiene dos columnas 'Parameter_Details' y 'Details'. Los detalles de la segunda columna deben ser editables. Las filas pueden variar según la selección de TreeViewItem.'EditItem' no está permitido para esta vista - WPF Edición de edición de datos

Por ejemplo, Mi TreeView tiene dos elementos, digamos
Jack
Jill

Cuando hago clic/seleccionar Jack, mi DataGrid 'Detalles del Estudiante espectáculos 1 fila con dos columnas Cadena 'Dirección' bajo' Parameter_Details 'column and string.Empty under' Details 'columns

Dirección |

Cuando hago clic/seleccionar Jill, shows '' StudentDetails mi DataGrid 2 filas con dos columnas primera fila: Cadena 'Apellido' en la columna '' y Parameter_Details String.Empty en 'Detalles' columnas segunda fila: Cadena 'Dirección' en 'Parameter_Details' columna y cadena. Vacío en 'Detalles' columnas Apellido | Dirección |

Estoy agregando datos a mi cuadrícula de datos usando el bucle foreach. Llego 'ParameterDetails' de DB donde cada fila ha de parámetros correspondientes a TreeViewItem

Cada vez que selecciono la TreeViewItem, hago la pieza adjunta de código:

dgStudentDetails.Items.Clear(); 

foreach (Parameter_Details entry in ParameterDetails) 
{ 
    if(entry.ID == SelectedTVItem.ID) 
    { 
     dgKeywordParameters.Items.Add(new Parameter_dgInput() { name = entry.Name, input = "" }); 
    } 
} 

los datos se enganchan a la cuadrícula de datos pero cuando estoy tratando de editar segunda columna usando

private void DataGridCell_PreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e) 
{ 
    DataGridCell cell = sender as DataGridCell; 

    if (cell != null && !cell.IsEditing && !cell.IsReadOnly) 
    { 
     // enables editing on single click 
     if (!cell.IsFocused) 
     cell.Focus(); 

     DataGrid dataGrid = UIHelpers.TryFindParent<DataGrid>(cell); 

     if (dataGrid != null) 
     { 
      if (dataGrid.SelectionUnit != DataGridSelectionUnit.FullRow) 
      { 
       if (!cell.IsSelected) 
         cell.IsSelected = true; 
      } 
      else 
      { 
        DataGridRow row = UIHelpers.TryFindParent<DataGridRow>(cell); 
        if (row != null && !row.IsSelected) 
        { 
         row.IsSelected = true; 
        } 
      } 
     } 
    } 
} 

me sale el siguiente error:

System.InvalidOperationException was unhandled 
    Message='EditItem' is not allowed for this view. 
    Source=PresentationFramework 
    StackTrace: 
     at System.Windows.Controls.ItemCollection.System.ComponentModel.IEditableCollectionView.EditItem(Object item) 
     at System.Windows.Controls.DataGrid.EditRowItem(Object rowItem) 
     at System.Windows.Controls.DataGrid.OnExecutedBeginEdit(ExecutedRoutedEventArgs e) 
     at System.Windows.Controls.DataGrid.OnExecutedBeginEdit(Object sender, ExecutedRoutedEventArgs e) 
     at System.Windows.Input.CommandBinding.OnExecuted(Object sender, ExecutedRoutedEventArgs e) 
     at System.Windows.Input.CommandManager.ExecuteCommandBinding(Object sender, ExecutedRoutedEventArgs e, CommandBinding commandBinding) 
     at System.Windows.Input.CommandManager.FindCommandBinding(CommandBindingCollection commandBindings, Object sender, RoutedEventArgs e, ICommand command, Boolean execute) 
     at System.Windows.Input.CommandManager.FindCommandBinding(Object sender, RoutedEventArgs e, ICommand command, Boolean execute) 
     at System.Windows.Input.CommandManager.OnExecuted(Object sender, ExecutedRoutedEventArgs e) 
     at System.Windows.UIElement.OnExecutedThunk(Object sender, ExecutedRoutedEventArgs e) 
     at System.Windows.Input.ExecutedRoutedEventArgs.InvokeEventHandler(Delegate genericHandler, Object target) 
     at System.Windows.RoutedEventArgs.InvokeHandler(Delegate handler, Object target) 
     at System.Windows.RoutedEventHandlerInfo.InvokeHandler(Object target, RoutedEventArgs routedEventArgs) 
     at System.Windows.EventRoute.InvokeHandlersImpl(Object source, RoutedEventArgs args, Boolean reRaised) 
     at System.Windows.UIElement.RaiseEventImpl(DependencyObject sender, RoutedEventArgs args) 
     at System.Windows.UIElement.RaiseEvent(RoutedEventArgs args, Boolean trusted) 
     at System.Windows.Input.RoutedCommand.ExecuteImpl(Object parameter, IInputElement target, Boolean userInitiated) 
     at System.Windows.Input.RoutedCommand.Execute(Object parameter, IInputElement target) 
     at System.Windows.Controls.DataGrid.BeginEdit(RoutedEventArgs editingEventArgs) 
     at System.Windows.Controls.DataGridCell.OnAnyMouseLeftButtonDown(MouseButtonEventArgs e) 
     at System.Windows.Controls.DataGridCell.OnAnyMouseLeftButtonDownThunk(Object sender, MouseButtonEventArgs e) 
     at System.Windows.Input.MouseButtonEventArgs.InvokeEventHandler(Delegate genericHandler, Object genericTarget) 
     at System.Windows.RoutedEventArgs.InvokeHandler(Delegate handler, Object target) 
     at System.Windows.RoutedEventHandlerInfo.InvokeHandler(Object target, RoutedEventArgs routedEventArgs) 
     at System.Windows.EventRoute.InvokeHandlersImpl(Object source, RoutedEventArgs args, Boolean reRaised) 
     at System.Windows.UIElement.ReRaiseEventAs(DependencyObject sender, RoutedEventArgs args, RoutedEvent newEvent) 
     at System.Windows.UIElement.OnMouseDownThunk(Object sender, MouseButtonEventArgs e) 
     at System.Windows.Input.MouseButtonEventArgs.InvokeEventHandler(Delegate genericHandler, Object genericTarget) 
     at System.Windows.RoutedEventArgs.InvokeHandler(Delegate handler, Object target) 
     at System.Windows.RoutedEventHandlerInfo.InvokeHandler(Object target, RoutedEventArgs routedEventArgs) 
     at System.Windows.EventRoute.InvokeHandlersImpl(Object source, RoutedEventArgs args, Boolean reRaised) 
     at System.Windows.UIElement.RaiseEventImpl(DependencyObject sender, RoutedEventArgs args) 
     at System.Windows.UIElement.RaiseTrustedEvent(RoutedEventArgs args) 
     at System.Windows.UIElement.RaiseEvent(RoutedEventArgs args, Boolean trusted) 
     at System.Windows.Input.InputManager.ProcessStagingArea() 
     at System.Windows.Input.InputManager.ProcessInput(InputEventArgs input) 
     at System.Windows.Input.InputProviderSite.ReportInput(InputReport inputReport) 
     at System.Windows.Interop.HwndMouseInputProvider.ReportInput(IntPtr hwnd, InputMode mode, Int32 timestamp, RawMouseActions actions, Int32 x, Int32 y, Int32 wheel) 
     at System.Windows.Interop.HwndMouseInputProvider.FilterMessage(IntPtr hwnd, WindowMessage msg, IntPtr wParam, IntPtr lParam, Boolean& handled) 
     at System.Windows.Interop.HwndSource.InputFilterMessage(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled) 
     at MS.Win32.HwndWrapper.WndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled) 
     at MS.Win32.HwndSubclass.DispatcherCallbackOperation(Object o) 
     at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs) 
     at MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(Object source, Delegate method, Object args, Int32 numArgs, Delegate catchHandler) 
     at System.Windows.Threading.Dispatcher.InvokeImpl(DispatcherPriority priority, TimeSpan timeout, Delegate method, Object args, Int32 numArgs) 
     at MS.Win32.HwndSubclass.SubclassWndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam) 
     at MS.Win32.UnsafeNativeMethods.DispatchMessage(MSG& msg) 
     at System.Windows.Threading.Dispatcher.PushFrameImpl(DispatcherFrame frame) 
     at System.Windows.Threading.Dispatcher.PushFrame(DispatcherFrame frame) 
     at System.Windows.Application.RunDispatcher(Object ignore) 
     at System.Windows.Application.RunInternal(Window window) 
     at System.Windows.Application.Run(Window window) 
     at System.Windows.Application.Run() 
     at EBS.App.Main() in C:\projects\EBS\EBS\obj\x86\Debug\App.g.cs:line 0 
     at System.AppDomain._nExecuteAssembly(RuntimeAssembly 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, Boolean ignoreSyncCtx) 
     at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state) 
     at System.Threading.ThreadHelper.ThreadStart() 
    InnerException: 

Respuesta

4

También he tenido este error. Parece que hay muchas causas posibles para el mismo mensaje de error.

Creo que en su caso puede funcionar para hacer lo que hice. Creo que el problema es que DataGrid lanzará este error al editar datos si los datos encuadernados no son uno de los tipos en los que permitirá la edición.

Lo que parece funcionar bien para mí, es si creo una nueva lista de lo que quiero mostrar (tal vez una clase que hago para ese fin, donde defino cada columna en la cuadrícula), y luego unir el DataGrid a esa lista.

Usted puede ver mi Q & A sobre esto en: Why does one of MY WPF DataGrids give the "'EditItem' is not allowed for this view" exception?

Cuestiones relacionadas