Windows Application的Form上放置一个PropertyGrid。
在PropertyGrid的PropertyValueChanged事件里,我想知道changedItem的父GridItem。
打个比方,changedItem是Bold,它的父GridItem是Font。
我怎样取得Font这个父GridItem。
这是我的代码:
0->private void propertyGrid1_PropertyValueChanged(object s, System.Windows.Forms.PropertyValueChangedEventArgs e)
1->{
2->        GridItem item = e.ChangedItem;
3->         if(item.Parent!=null)
4->        {
5->             this.label1.Text = item.Parent.Label;
6->        }
7->        else
8->             this.label1.Text = "null";
9->}
RunTime下改变Bold的Value
在执行到第三行时,扔出异常:
An unhandled exception of type 'System.ObjectDisposedException' occurred in system.windows.forms.dll
Additional information: Cannot access a disposed object named "The GridItem has been disposed and is no longer usable.".
似乎是e.ChangedItem的父GridItem被释放掉了。
后来我修改了我的代码Line 2为:
GridItem item = this.propertyGrid1.SelectedGridItem;
仍然会扔出Exception。
谁能告诉我为什么会扔出这样的Exception,还有要实现我的功能,即取出changedItem的父GridItem,应该怎样做?