I have a three-level hierarchical grid that shows Matches/Teams/Players. The display works fine.
Now I'm trying to drag-and-drop items onto that grid and need to know which row I'm over when the drop occurs.
Per some of your examples, I've added an event handler for the RowLoaded/Unloaded events in which I add event handlers for MouseEnter/Leave for each row. This works fine for the top (Game) level of the grid, and second (Teams) level, but when I add any event handlers for the Players grid, I'm having problems.
If all three levels have event handlers, when I attempt to expand the top-level grid, I get an exception as shown below. This happens regardless of whether I have separate event handlers for each level, or a shared/generic handler. As soon as I remove the event handlers (RowLoaded in this code snippet) in my third-level child grid, everything's fine, except of course that my application doesn't work. :)
Baffled and stuck.
-Lynne W
Example of the XAML with event handlers for RowLoaded/Unloaded. Same thing happens for MouseEnter/Leave. This causes the exception shown at the end of this message.
Event handling code for Player row event handlers
Exception thrown when a third-level child grid has extant/active event handlers
System.NullReferenceException was unhandled by user code
Message=Object reference not set to an instance of an object.
Source=ccm3
StackTrace:
at ccm3.ContentControls.ucMatchManagement.System.Windows.Markup.IStyleConnector.Connect(Int32 connectionId, Object target) in f:\PredatorGames\src\ccm3\trunk\ccm3\ContentControls\ucMatchManagement.xaml:line 245
at System.Windows.FrameworkTemplate.LoadTemplateXaml(XamlReader templateReader, XamlObjectWriter currentWriter)
at System.Windows.FrameworkTemplate.LoadTemplateXaml(XamlObjectWriter objectWriter)
at System.Windows.FrameworkTemplate.LoadOptimizedTemplateContent(DependencyObject container, IComponentConnector componentConnector, IStyleConnector styleConnector, List`1 affectedChildren, UncommonField`1 templatedNonFeChildrenField)
at System.Windows.FrameworkTemplate.LoadContent(DependencyObject container, List`1 affectedChildren)
at System.Windows.FrameworkTemplate.LoadContent()
at Telerik.Windows.Controls.GridView.GridViewRow.PopulateHierarchyContent() in c:\TB\102\WPF_Scrum\Release_WPF_40\Sources\Development\Controls\GridView\GridView\GridView\Rows\GridViewRow.cs:line 304
at Telerik.Windows.Controls.GridView.GridViewRow.OnIsExpandedChanged(Boolean oldValue, Boolean newValue) in c:\TB\102\WPF_Scrum\Release_WPF_40\Sources\Development\Controls\GridView\GridView\GridView\Rows\GridViewRow.cs:line 230
at Telerik.Windows.Controls.GridView.GridViewRow.OnIsExpandedChanged(DependencyObject dependencyObject, DependencyPropertyChangedEventArgs e) in c:\TB\102\WPF_Scrum\Release_WPF_40\Sources\Development\Controls\GridView\GridView\GridView\Rows\GridViewRow.cs:line 205
at System.Windows.DependencyObject.OnPropertyChanged(DependencyPropertyChangedEventArgs e)
at System.Windows.FrameworkElement.OnPropertyChanged(DependencyPropertyChangedEventArgs e)
at System.Windows.DependencyObject.NotifyPropertyChange(DependencyPropertyChangedEventArgs args)
at System.Windows.DependencyObject.UpdateEffectiveValue(EntryIndex entryIndex, DependencyProperty dp, PropertyMetadata metadata, EffectiveValueEntry oldEntry, EffectiveValueEntry& newEntry, Boolean coerceWithDeferredReference, Boolean coerceWithCurrentValue, OperationType operationType)
at System.Windows.DependencyObject.SetValueCommon(DependencyProperty dp, Object value, PropertyMetadata metadata, Boolean coerceWithDeferredReference, Boolean coerceWithCurrentValue, OperationType operationType, Boolean isInternal)
at MS.Internal.Data.PropertyPathWorker.SetValue(Object item, Object value)
at MS.Internal.Data.ClrBindingWorker.UpdateValue(Object value)
at System.Windows.Data.BindingExpression.UpdateSource(Object value)
InnerException:
Now I'm trying to drag-and-drop items onto that grid and need to know which row I'm over when the drop occurs.
Per some of your examples, I've added an event handler for the RowLoaded/Unloaded events in which I add event handlers for MouseEnter/Leave for each row. This works fine for the top (Game) level of the grid, and second (Teams) level, but when I add any event handlers for the Players grid, I'm having problems.
If all three levels have event handlers, when I attempt to expand the top-level grid, I get an exception as shown below. This happens regardless of whether I have separate event handlers for each level, or a shared/generic handler. As soon as I remove the event handlers (RowLoaded in this code snippet) in my third-level child grid, everything's fine, except of course that my application doesn't work. :)
Baffled and stuck.
-Lynne W
Example of the XAML with event handlers for RowLoaded/Unloaded. Same thing happens for MouseEnter/Leave. This causes the exception shown at the end of this message.
<
telerik:RadGridView
Name
=
"gridMatchPlayers"
AutoGenerateColumns
=
"False"
ItemsSource
=
"{Binding MatchPlayers}"
ShowGroupPanel
=
"False"
RowLoaded
=
"MatchPlayerGrid_RowLoaded"
RowUnloaded
=
"MatchPlayerGrid_RowUnloaded"
telerikDragDrop:RadDragAndDropManager.AllowDrag
=
"False"
telerikDragDrop:RadDragAndDropManager.AllowDrop
=
"True"
>
Event handling code for Player row event handlers
- Note that I have the add'l MouseEnter/Leave event handlers commented out. I've tried Row and Mouse event handlers for my Player (third-level) grid and they cause the exception seen below.
////////////////////////////////////////////////////////////////////////////////
// //
// ////// MatchPlayer grid
// //
//
void
MatchPlayerGrid_RowLoaded(Object sender, Telerik.Windows.Controls.GridView.RowLoadedEventArgs e) {
var row = e.Row
as
GridViewRow;
if
(row !=
null
) {
//row.MouseEnter += new MouseEventHandler(MatchPlayerGridRow_MouseEnter);
//row.MouseLeave += new MouseEventHandler(MatchPlayerGridRow_MouseLeave);
}
}
void
MatchPlayerGrid_RowUnloaded(
object
sender, RowUnloadedEventArgs e) {
var row = e.Row
as
GridViewRow;
if
(row !=
null
) {
//row.MouseEnter += new MouseEventHandler(MatchPlayerGridRow_MouseEnter);
//row.MouseLeave += new MouseEventHandler(MatchPlayerGridRow_MouseLeave);
}
}
void
MatchPlayerGridRow_MouseEnter(Object sender, System.Windows.Input.MouseEventArgs e) {
var senderElement = e.OriginalSource
as
FrameworkElement;
var mouseOverRow = senderElement.ParentOfType<GridViewRow>();
}
void
MatchPlayerGridRow_MouseLeave(Object sender, MouseEventArgs e) {
var senderElement = e.OriginalSource
as
FrameworkElement;
var mouseExitRow = senderElement.ParentOfType<GridViewRow>();
}
Exception thrown when a third-level child grid has extant/active event handlers
System.NullReferenceException was unhandled by user code
Message=Object reference not set to an instance of an object.
Source=ccm3
StackTrace:
at ccm3.ContentControls.ucMatchManagement.System.Windows.Markup.IStyleConnector.Connect(Int32 connectionId, Object target) in f:\PredatorGames\src\ccm3\trunk\ccm3\ContentControls\ucMatchManagement.xaml:line 245
at System.Windows.FrameworkTemplate.LoadTemplateXaml(XamlReader templateReader, XamlObjectWriter currentWriter)
at System.Windows.FrameworkTemplate.LoadTemplateXaml(XamlObjectWriter objectWriter)
at System.Windows.FrameworkTemplate.LoadOptimizedTemplateContent(DependencyObject container, IComponentConnector componentConnector, IStyleConnector styleConnector, List`1 affectedChildren, UncommonField`1 templatedNonFeChildrenField)
at System.Windows.FrameworkTemplate.LoadContent(DependencyObject container, List`1 affectedChildren)
at System.Windows.FrameworkTemplate.LoadContent()
at Telerik.Windows.Controls.GridView.GridViewRow.PopulateHierarchyContent() in c:\TB\102\WPF_Scrum\Release_WPF_40\Sources\Development\Controls\GridView\GridView\GridView\Rows\GridViewRow.cs:line 304
at Telerik.Windows.Controls.GridView.GridViewRow.OnIsExpandedChanged(Boolean oldValue, Boolean newValue) in c:\TB\102\WPF_Scrum\Release_WPF_40\Sources\Development\Controls\GridView\GridView\GridView\Rows\GridViewRow.cs:line 230
at Telerik.Windows.Controls.GridView.GridViewRow.OnIsExpandedChanged(DependencyObject dependencyObject, DependencyPropertyChangedEventArgs e) in c:\TB\102\WPF_Scrum\Release_WPF_40\Sources\Development\Controls\GridView\GridView\GridView\Rows\GridViewRow.cs:line 205
at System.Windows.DependencyObject.OnPropertyChanged(DependencyPropertyChangedEventArgs e)
at System.Windows.FrameworkElement.OnPropertyChanged(DependencyPropertyChangedEventArgs e)
at System.Windows.DependencyObject.NotifyPropertyChange(DependencyPropertyChangedEventArgs args)
at System.Windows.DependencyObject.UpdateEffectiveValue(EntryIndex entryIndex, DependencyProperty dp, PropertyMetadata metadata, EffectiveValueEntry oldEntry, EffectiveValueEntry& newEntry, Boolean coerceWithDeferredReference, Boolean coerceWithCurrentValue, OperationType operationType)
at System.Windows.DependencyObject.SetValueCommon(DependencyProperty dp, Object value, PropertyMetadata metadata, Boolean coerceWithDeferredReference, Boolean coerceWithCurrentValue, OperationType operationType, Boolean isInternal)
at MS.Internal.Data.PropertyPathWorker.SetValue(Object item, Object value)
at MS.Internal.Data.ClrBindingWorker.UpdateValue(Object value)
at System.Windows.Data.BindingExpression.UpdateSource(Object value)
InnerException: