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
4 Answers, 1 is accepted
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 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

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!

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;
}
}
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