Bind dependency property in custom column

5 posts, 0 answers
  1. David
    David avatar
    8 posts
    Member since:
    Mar 2011

    Posted 05 Jul Link to this post

    I created a custom column that derives from GridViewBoundColumnBase. The column defines the dependency property SearchType.

    I would like to bind this property to the field "ArticleType" while the DataMemberBinding binds to "Article".

    <controlsBaseGridViewColumns:GridViewSearchColumn UniqueName="Article" Width="*" MinWidth="150" DataMemberBinding="{Binding Article, Mode=TwoWay}" SortMemberPath="Article.LookupValue" SearchType="{Binding ArticleType, Converter={StaticResource searchTypeConverter}}" Header="Artikel" />

    The binding produces the following runtime error:

    System.Windows.Data Error: 40 : BindingExpression path error: 'ArticleType' property not found on 'object' ''OrderItem' (HashCode=19537849)'. BindingExpression:Path=ArticleType; DataItem='OrderItem' (HashCode=19537849); target element is 'GridViewSearchColumn' (HashCode=4419325); target property is 'SearchType' (type 'SearchTypes')

    Can you please help me out?

    Thanks for your support!

     

     

    e

  2. Dilyan Traykov
    Admin
    Dilyan Traykov avatar
    370 posts

    Posted 07 Jul Link to this post

    Hello David,

    It seems that the ArticleType property you're trying to bind to does not exist in the OrderItem business object. Is that the case? If so, could you try instead binding the SearchType property to Article.ArticleType?

    If this modification does not resolve the issue, could you please provide more details about the exact setup at your end? Specifying the properties of the OrderItem and Article objects would definitely be of help. If possible, please also provide the code behind your GridViewSearchColumn.

    Thank you in advance for your cooperation.

    Regards,
    Dilyan Traykov
    Telerik by Progress
    Do you need help with upgrading your AJAX, WPF or WinForms project? Check the Telerik API Analyzer and share your thoughts.
  3. UI for WPF is Visual Studio 2017 Ready
  4. David
    David avatar
    8 posts
    Member since:
    Mar 2011

    Posted 07 Jul Link to this post

    Hello Dilyan,

    thanks for your response!

    In my original post I tried to simplify the error message by replacing the original object names by common names like "orderitem" and I just saw that I made a mistake.

    So here is the correct and complete scenario:

    I assigned an observable collection of InvoicingInstitutionContractGroupSpecialToolID objects to the itemssource property of the grid. This object contains the properties ArticleType and Article.

    The XAML definition of the grid is:

    <telerik:RadGridView x:Name="gridView" AutoGenerateColumns="False" IsFilteringAllowed="False">
      <telerik:RadGridView.Columns>
        <controlsBaseGridViewColumns:GridViewLookupKeyColumn UniqueName="ArticleType" Width="130" MinWidth="100" DataMemberBinding="{Binding ArticleType, Mode=TwoWay}" KeyName="ArtikelTyp" Header="Artikeltyp" />
        <controlsBaseGridViewColumns:GridViewSearchColumn UniqueName="Article" Width="*" MinWidth="150" DataMemberBinding="{Binding Article, Mode=TwoWay}" SortMemberPath="Article.LookupValue" SearchType="{Binding ArticleType, Converter={StaticResource searchTypeConverter}}" Header="Artikel" />
      </telerik:RadGridView.Columns>
      <telerik:RadGridView.SortDescriptors>
        <telerik:SortDescriptor Member="Article.LookupValue" SortDirection="Ascending" />
      </telerik:RadGridView.SortDescriptors>           
    </controlsBaseGridView:GridView >

    After assigning the itemssource, I get the following runtime error message:

    System.Windows.Data Error: 40 : BindingExpression path error: 'ArticleType' property not found on 'object' ''InvoicingInstitutionMasterData' (HashCode=2569762)'. BindingExpression:Path=ArticleType; DataItem='InvoicingInstitutionMasterData' (HashCode=2569762); target element is 'GridViewSearchColumn' (HashCode=35481661); target property is 'SearchType' (type 'SearchTypes')

    The point is, that the datacontext contains the InvoicingInstutitionMasterData object, but this object is irrelevant for the grid. It seems that the binding of the column's ArticleType property doesn't bind to the row item, but to the datacontext. Do I have to define a binding with relative source to address to row item and not the datacontext?

    I hope I made it clearer.

     

    Thanks!

  5. David
    David avatar
    8 posts
    Member since:
    Mar 2011

    Posted 07 Jul Link to this post

    I forgot the definition of the GridViewSearchColumn. So here it is:

    public class GridViewSearchColumn : GridViewBoundColumnBase
    {
        public static readonly DependencyProperty SearchTypeProperty = DependencyProperty.Register("SearchType", typeof(SearchTypes), typeof(GridViewSearchColumn), new PropertyMetadata(SearchTypes.Commodity));
     
        public SearchTypes SearchType
        {
            get { return (SearchTypes)GetValue(SearchTypeProperty); }
            set { SetValue(SearchTypeProperty, value); }
        }
     
        public override System.Windows.FrameworkElement CreateCellEditElement(Telerik.Windows.Controls.GridView.GridViewCell cell, object dataItem)
        {
            var searchBox = new SearchBox();
            searchBox.Init(this.AppContext);
            searchBox.SearchType = this.SearchType;
            searchBox.PreCondition = this.PreCondition;
            searchBox.IsReadOnly = ((GridView)this.Parent).IsReadOnly;
            searchBox.SetBinding(SearchBox.SelectedValueProperty, new Binding() { Mode = BindingMode.TwoWay, NotifyOnValidationError = true, ValidatesOnExceptions = true, UpdateSourceTrigger = System.Windows.Data.UpdateSourceTrigger.LostFocus, Path = new System.Windows.PropertyPath(this.DataMemberBinding.Path.Path) });
            return searchBox;
        }
     
     
    }

  6. Dilyan Traykov
    Admin
    Dilyan Traykov avatar
    370 posts

    Posted 11 Jul Link to this post

    Hello David,

    Unfortunately, I'm unable to reproduce the issue you've described using just the code you've provided.
    However, I believe the following line may be causing the change of the data context:

    searchBox.Init(this.AppContext);

    It would be of help if you could share more information about your SearchBox class and its Init method.

    Additionally, could you please have a look at the Create Custom Column Editor article and see whether your implementation differs from the approach described in there in any way?

    Regards,
    Dilyan Traykov
    Telerik by Progress
    Do you need help with upgrading your AJAX, WPF or WinForms project? Check the Telerik API Analyzer and share your thoughts.
Back to Top
UI for WPF is Visual Studio 2017 Ready