Problems databinding

7 posts, 0 answers
  1. MrHinsh [MVP]
    MrHinsh [MVP] avatar
    5 posts
    Member since:
    Jul 2008

    Posted 25 Jul 2008 Link to this post

    Hi, I am having a little problem with databinding against the Treeview in WPF.

    This is my data template

    1  <DataTemplate x:Key="TreeParameterDataTemplate" DataType="TreeParameter">  
    2             <StackPanel>                  
    3                 <Telerik:RadTreeView  
    4                  VerticalAlignment="Top" 
    5                  HorizontalAlignment="Left" 
    6                  MinHeight="100" 
    7                  x:Name="myTreeview" 
    8                  Margin="0, 0, 20, 0" 
    9                  SelectionMode="Single" 
    10               
    11                  SelectedValuePath="{Binding Path=ParameterValue, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" 
    12                  ItemsSource="{Binding Path=Nodes, Mode=Default}" 
    13                  ItemTemplate="{DynamicResource ValidValueNodeDataTemplate}" 
    14                  IsTriStateMode="True" 
    15                  IsOptionElementsEnabled="True" 
    16                  ItemsOptionListType="CheckList">  
    17             </Telerik:RadTreeView> 
    18                 <!--<ListBox ItemTemplate="{DynamicResource ValidValueNodeDataTemplate}"  ItemsSource="{Binding Path=Nodes, Mode=Default}" />--> 
    19             </StackPanel> 
    20     </DataTemplate> 

    It seams to be the SelectedValuePath that is causing the problem. It should be a string, and ParameterValue is a string, but I get the following error:

    System.InvalidOperationException was unhandled  
      Message="Syntax error in PropertyPath 'Syntax error in Binding.Path '[Business Hierarchy].[Power Pack Hierarchy].[Power Pack Description].&[Aggreko International]' ... '&[Chile]&[1]'.'." 
      Source="PresentationFramework" 
      StackTrace:  
           at System.Windows.PropertyPath.PrepareSourceValueInfo(ITypeDescriptorContext typeDescriptorContext)  
           at System.Windows.PropertyPath..ctor(String path, Object[] pathParameters)  
           at Telerik.Windows.Controls.RadTreeView.GetSelectedValuePathBinding()  
           at Telerik.Windows.Controls.RadTreeView.UpdateSelectedValue()  
           at Telerik.Windows.Controls.RadTreeView.SelectionChanger_SelectionChanged(Object sender, SelectionChangedEventArgs e)  
           at Telerik.Windows.Controls.SelectionChanger`1.InvokeSelectionChangedEvent()  
           at Telerik.Windows.Controls.SelectionChanger`1.End()  
           at Telerik.Windows.Controls.SelectionChanger`1.InsertItem(Int32 index, T item)  
           at System.Collections.ObjectModel.Collection`1.Add(T item)  
           at Telerik.Windows.Controls.RadTreeViewItem.OnIsSelectedPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs args)  
           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, OperationType operationType)  
           at System.Windows.DependencyObject.SetValueCommon(DependencyProperty dp, Object value, PropertyMetadata metadata, Boolean coerceWithDeferredReference, OperationType operationType, Boolean isInternal)  
           at System.Windows.DependencyObject.SetValue(DependencyProperty dp, Object value)  
           at Telerik.Windows.Controls.RadTreeViewItem.set_IsSelected(Boolean value)  
           at Telerik.Windows.Controls.RadTreeView.SetSelectedItem(RadTreeViewItem itemContainer)  
           at Telerik.Windows.Controls.RadTreeView.HandleItemSelectionFromUI(RadTreeViewItem itemUnderCursor)  
           at Telerik.Windows.Controls.RadTreeViewItem.OnHeaderMouseLeftButtonDown(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.CrackMouseButtonEventAndReRaiseEvent(DependencyObject sender, MouseButtonEventArgs e)  
           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.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, Int32 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, Boolean isSingleParameter)  
           at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Boolean isSingleParameter, Delegate catchHandler)  
           at System.Windows.Threading.Dispatcher.WrappedInvoke(Delegate callback, Object args, Boolean isSingleParameter, Delegate catchHandler)  
           at System.Windows.Threading.Dispatcher.InvokeImpl(DispatcherPriority priority, TimeSpan timeout, Delegate method, Object args, Boolean isSingleParameter)  
           at System.Windows.Threading.Dispatcher.Invoke(DispatcherPriority priority, Delegate method, Object arg)  
           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.Threading.Dispatcher.Run()  
           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 Aggreko.ABI.ABIReportViewer.Application.Main() in C:\Working\Workspaces\ATFS01\Sirius\DEV\R699\Aggreko.ABI.ABIReportViewer\obj\Debug\Application.g.vb:line 73  
           at System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)  
           at System.AppDomain.nExecuteAssembly(Assembly assembly, String[] args)  
           at System.Runtime.Hosting.ManifestRunner.Run(Boolean checkAptModel)  
           at System.Runtime.Hosting.ManifestRunner.ExecuteAsAssembly()  
           at System.Runtime.Hosting.ApplicationActivator.CreateInstance(ActivationContext activationContext, String[] activationCustomData)  
           at System.Runtime.Hosting.ApplicationActivator.CreateInstance(ActivationContext activationContext)  
           at System.Activator.CreateInstance(ActivationContext activationContext)  
           at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssemblyDebugInZone()  
           at System.Threading.ThreadHelper.ThreadStart_Context(Object state)  
           at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)  
           at System.Threading.ThreadHelper.ThreadStart()  
      InnerException:   
     

    Help...
  2. Valentin.Stoychev
    Admin
    Valentin.Stoychev avatar
    2198 posts

    Posted 25 Jul 2008 Link to this post

    Hi Martin,

    Are you trying to bind it to XML? We have a known issue with XML and SelectedValuePath property that we will try to address for the ServicePack.

    Can you try if the same setup works with the MS treeview?

    Kind regards,
    Valentin.Stoychev
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
  3. MrHinsh [MVP]
    MrHinsh [MVP] avatar
    5 posts
    Member since:
    Jul 2008

    Posted 25 Jul 2008 Link to this post

    Hi, Yes the problem occurs even using the the MS treeview!

    :(

    However the code is the same for other bits, like:

    <DataTemplate x:Key="DateTimeParameterDataTemplate">  
            <StackPanel> 
                <Telerik:RadCalendar SelectedDate="{Binding Path=ParameterValue, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" /> 
            </StackPanel> 
        </DataTemplate> 

    Which work just fine....

    I thought that the SelectedValuePath parameter was a string?
  4. Valentin.Stoychev
    Admin
    Valentin.Stoychev avatar
    2198 posts

    Posted 25 Jul 2008 Link to this post

    Hi Martin,

    Here is a very useful article about using the SelectedValue, SelectedValuePath, and SelectedItem
    http://msdn.microsoft.com/en-us/library/ms788714.aspx

    Regards,
    Valentin.Stoychev
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
  5. MrHinsh [MVP]
    MrHinsh [MVP] avatar
    5 posts
    Member since:
    Jul 2008

    Posted 25 Jul 2008 Link to this post

    Hi Valentin,

     That does not help me :(

     I am trying to bind the SelectedValuePath to a string value of an object!

     The object that I bind to the TreeView has both a property called "Nodes" that contains the herarchical items, and a property called "ParameterValue" that will contain the selected ietm. This is a string property and I have many other controls binding to it with no problems with other types of data.

    Why can't I pull the string value of SelectedValuePath and bind it to a string property on an object?

    Would it matter that my data has some funny charicters in it? e.g. "[Business Hierarchy].[Business Hierarchy].[Region].&[EUROPE]"

    Martin
  6. MrHinsh [MVP]
    MrHinsh [MVP] avatar
    5 posts
    Member since:
    Jul 2008

    Posted 25 Jul 2008 Link to this post

    Hi,

     I have been able to output the SelectedValue to a text area, but I do not see how to get the current selected item and set the current selected item into my data object.

    Here is the portion of my ResourceDictionary:

     <DataTemplate x:Key="TreeParameterDataTemplate" DataType="TreeParameter">  
                <StackPanel> 
                <TreeView ItemsSource="{Binding Path=Nodes, Mode=Default}" ItemTemplate="{DynamicResource ValidValueNodeDataTemplate}">  
                     
               </TreeView> 
               
     
                 <Telerik:RadTreeView  
                     VerticalAlignment="Top" 
                     HorizontalAlignment="Left" 
                     MinHeight="100" 
                     x:Name="myTreeview" 
                     Margin="0, 0, 20, 0" 
                     SelectionMode="Single" 
                     SelectedValuePath="ValidValue.Value"   
                     ItemsSource="{Binding Path=Nodes, Mode=Default}" 
                     ItemTemplate="{DynamicResource ValidValueNodeDataTemplate}" 
                     IsTriStateMode="True" 
                     IsOptionElementsEnabled="True" 
                     ItemsOptionListType="CheckList">  
                </Telerik:RadTreeView> 
                <TextBlock Margin="10,0,0,0" Text="{Binding ElementName=myTreeView, Path=SelectedValuePath}" 
               Foreground="Blue"/>  
     
                <TextBlock Margin="10">SelectedValue:</TextBlock> 
                <TextBlock Margin="10,0,0,0"   
               Text="{Binding ElementName=myTreeView,   
                              Path=SelectedValue}"  
               Foreground="Blue"/>  
                <!--<ListBox ItemTemplate="{DynamicResource ValidValueNodeDataTemplate}"  ItemsSource="{Binding Path=Nodes, Mode=Default}" />--> 
                </StackPanel> 
        </DataTemplate> 
    This displayes the result on the screen, but I need to add a binding from the selected value to my object...
  7. Valentin.Stoychev
    Admin
    Valentin.Stoychev avatar
    2198 posts

    Posted 28 Jul 2008 Link to this post

    Hi Martin,

    I'm glad you were able to resolve the problem with SelectedValue.

    You can get the selected item by using the SelectedItem property of the RadTreeView, or if you have multiple selection enabled by using the SelectedItems collection.

    Greetings,
    Valentin.Stoychev
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
Back to Top