I am new to WPF and this binding error is making me crazy. I have a datatemplate which has combobox. That datatemplate is used by gridview column. I am trying to bind the combobox to csla object but it is throwing me below error:
System.Windows.Data Error: 40 : BindingExpression path error:
'oChargeCodesValidvalues' property not found on 'object' ''EditGridCellData' (HashCode=59067897)'. BindingExpression:Path=DataContext.oChargeCodesValidvalues; DataItem='ComboBox' (Name=''); target element is 'ComboBox' (Name=''); target property is 'ItemsSource' (type 'IEnumerable')
here is the snippet of my xaml:
<DataTemplate x:Key="combodescriptionTemplate">
<ComboBox Name="cboCodeValidValues" ItemsSource="{Binding DataContext.oChargeCodesValidvalues, RelativeSource={RelativeSource Mode=Self}}">
<ComboBox.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding Description}" />
</DataTemplate>
</ComboBox.ItemTemplate>
</ComboBox>
</DataTemplate>
<local:TotalCellTemplateSelector x:Key="totalcellTemplateSelector"
combodescriptionTemplate="{StaticResource combodescriptionTemplate}"/>
Some more info based on the comments: I am using a devexpress gridview in wcf. There are 2 columns both bounded to field. First is combobox and second is textbox by default and combo based on value of first column.The gridview datasource is code csla object. ChargeCodeValidValues is cslaobjcet . And i used datatemplate to change editor of second column.
Below is the code snippet of my ChargeCodeValidValues object:
public class ChargeCodeValidValues
{
public DataTable ChargeCodesValidValuesTable { get; set; }
public ChargeCodeValidValues()
{
LoadChargeCodesValidValues();
}
public void LoadChargeCodesValidValues()
{
//get data from db
}
calling in code:
private ChargeCodeValidValues oChargeCodesValidvalues;
oChargeCodesValidvalues = new ChargeCodeValidValues();
and i am trying to bind combox to oChargeCodesValidvalues and getting above error.
Here is the snippet of my TotalCellTemplateSelector:
public DataTemplate combodescriptionTemplate { get; set; }
public override DataTemplate SelectTemplate(object item, DependencyObject container)
{
GridCellData cellData = item as GridCellData;
if (cellData != null)
{
RowData rowdata = cellData.RowData;
DataRowView rowview = rowdata.Row as DataRowView;
if (rowview != null)
{
DataRow drCC = rowview.Row;
//if(drCC.Field<int>("FieldName") != DBNull.Value)
//{
int Code = drCC.Field<int>("FieldName", 0);
if (Code == Value)
return combodescriptionTemplate;
else
return null;
// }
}
DataContextoflocal:TotalCellTemplateSelector? I guess it could be the problem that you set the wrongDataContextor as @ChrisF mentioned you have got a typo.