- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一个 TreeView 学生。我在 TreeView 中的项目是类(class)中学生的姓名。在 TreeView 中选择一个项目时,我的 DataGrid“StudentDetails”中的数据应该发生变化。我的 DataGrid 有两列“Parameter_Details”和“Details”。第二列详细信息应该是可编辑的。行可能会根据 TreeViewItem 的选择而变化。
例如,我的 TreeView 有两个项目,例如
jack
吉尔
当我单击/选择 Jack 时,我的 DataGrid“学生详细信息”显示 1 行两列“Parameter_Details”列下的字符串“Address”和“详细信息”列下的 string.Empty
地址|
当我单击/选择 Jill 时,我的 DataGrid“StudentDetails”显示 2 行两列第一行:“Parameter_Details”列下的字符串“Last Name”和“详细信息”列下的 string.Empty第二行:“Parameter_Details”列下的字符串“Address”和“Details”列下的 string.Empty姓氏|地址 |
我正在使用 foreach 循环将数据添加到我的数据网格中。我从数据库中获取“ParameterDetails”,其中每行都有与 TreeviewItem 对应的参数
每当我选择 TreeviewItem 时,我都会执行附加的代码:
dgStudentDetails.Items.Clear();
foreach (Parameter_Details entry in ParameterDetails)
{
if(entry.ID == SelectedTVItem.ID)
{
dgKeywordParameters.Items.Add(new Parameter_dgInput() { name = entry.Name, input = "" });
}
}
数据被绑定(bind)到数据网格,但是当我尝试使用编辑第二列时
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;
}
}
}
}
}
我收到以下错误:
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:
最佳答案
我也遇到过这个错误。看来同一错误消息有多种可能的原因。
我认为在你的情况下,做我所做的可能会起作用。我认为问题是,如果绑定(bind)数据不是允许编辑的类型之一,DataGrid 在编辑数据时会抛出此错误。
对我来说似乎效果很好的是,如果我创建一个新的列表,其中包含我想要显示的内容(可能是我为此目的创建的类,我在其中定义网格中的每一列),然后将 DataGrid 绑定(bind)到该列表。
您可以在以下位置查看我对此的问答: Why does one of MY WPF DataGrids give the "'EditItem' is not allowed for this view" exception?
关于wpf - 此 View 不允许“EditItem” - WPF 数据编辑问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8677757/
我可以访问 Gridview 页脚模板中的日历控件。但是在 EditItem 模板中做同样的事情并不是那么容易 有人可以建议怎么做吗? 我在 EditItem 模板中使用了 3 个控件:Calenda
我有一个数据网格,它获取这样的数据: public struct MyData { public string name { set; get; } p
我有一个 TabControl 并使用 DataGrid 在 TabControl 上添加 TabItem。但如果我双击范围崩溃: "EditItem" is not allowed for this
我有一个 TabControl 并使用 DataGrid 在 TabControl 上添加 TabItem。但是,如果我双击范围崩溃: "EditItem" is not allowed for th
我正在尝试以编程方式将项目添加到 DataGrid 并让用户编辑数据。但是,在尝试编辑数据时,我不断收到“此 View 不允许使用 EditItem”错误。我尝试制作我正在添加 ObservableC
我知道有很多关于该错误的问题(1、2、3、4、5 等),但我找不到可以解释原因的问题这个错误适合我的情况。如果我错过了一个,请告诉我! 首先,我绑定(bind)到我的 DataGrid ItemsSo
我有一个包含 2 个数据网格的窗口。如果我从第一个 DataGrid 中的一个特定列单击到另一个 DataGrid 的任何列,则会出现错误 DeferRefresh is not allowed du
我在 GUI 中有一个选项卡控件,并且其中一个选项卡中有 WPF 4.0 数据网格。当我单击网格中的单元格并编辑某些内容然后切换选项卡时,出现延迟刷新错误: DeferRefresh' is not
我有一个 TreeView 学生。我在 TreeView 中的项目是类(class)中学生的姓名。在 TreeView 中选择一个项目时,我的 DataGrid“StudentDetails”中的数据
我以编程方式添加 DataGrid: System.Windows.Controls.DataGrid dataGrid = new System.Windows.Controls.DataGrid(
我正在尝试使用自定义列表在数据网格上的 WPF 中进行数据绑定(bind)。我的自定义列表类包含 List 类型的私有(private)数据列表.我无法公开此列表,但是公开索引器以设置和获取单个项目。
我正在尝试向 QListWidget 添加一个项目,选择该项目,然后开始编辑新项目。 该项目被添加,它被选中,但该行没有被引入 QLineEdit,或者它试图使用的任何东西。 这是我的小部件的代码,相
我有一个 QTreeWidgetItem 添加到 QTreeWidget: QTreeWidgetItem* item = new QTreeWidgetItem(ui->trwPairs); ite
我有以下网格
我已经阅读了我可以在此处和 MS 论坛上找到的关于此异常的所有问答,并尝试了我理解的大部分建议以及其他一些建议。似乎这个异常可能出于多种原因出现。 与其他人一样,我有一个绑定(bind)到集合的 WP
好的,为了尝试找到这个问题的答案,我使用 AdventureWorks 数据库制作了一个更简单的项目。 我从 Vendor 和 PurchaseOrderHeader 表创建了一个模型 - 将它们作为
我已经阅读了至少 4 个小时,似乎是列表类型,但我有一个情况: 具有集合属性的 ObservableCollection。 我定义了第一个DataGrid,并且在section
我创建了一个包装器来扩展 ObservableCollection [Serializable] public abstract class ModelCollection : ModelCollec
我是一名优秀的程序员,十分优秀!