The expression contains object that is not defined in the current context.

3 posts, 1 answers
  1. Dominik
    Dominik avatar
    82 posts
    Member since:
    Dec 2012

    Posted 12 Jun 2013 Link to this post

    Hi,

    All columns in my grid are added manually in code. Then I set the grid DataSource so most columns are mapped via by FieldName. But there are also not mapped columns that contains expression. I have problem with filtering those columns.

    To get the error, do 3 quick steps:

    1. Add new form and then add new Grid with 4 columns (GridViewTextBoxColumn).
    2. Copy and paste code:
    private void Form1_Load(object sender, EventArgs e)
      {
          radGridView1.AllowEditRow = false;
          radGridView1.AllowAddNewRow = false;
          radGridView1.EnableFiltering = true;
          radGridView1.ShowFilteringRow = true;
          radGridView1.SelectionMode = GridViewSelectionMode.CellSelect;
     
          DataTable dt = new DataTable();
          dt.Columns.Add( new DataColumn("sql1", typeof(Int32)));
          dt.Columns.Add( new DataColumn("sql2", typeof(Int32)));
     
          dt.Rows.Add(new Object[] { 1, 0 });
          dt.Rows.Add(new Object[] { 1, 1 });
          dt.Rows.Add(new Object[] { 1, 1 });
          dt.Rows.Add(new Object[] { 0, 1 });
          dt.Rows.Add(new Object[] { 1, 0 });
          dt.Rows.Add(new Object[] { 1, 1 });
          dt.Rows.Add(new Object[] { 1, 0 });
     
     
          radGridView1.DataSource = dt;
     
          radGridView1.Columns[2].Expression = "IIF(column1 = 1,  'YES', 'NO' )";
          radGridView1.Columns[3].Expression = "IIF(column2 = 1,  'YES', 'NO' )";
      }


    3. Run application and add filter: "y" to column 3, then enter "y" to column 4.

    You will get error like in title of this post.

    Output:
    A first chance exception of type 'Telerik.WinControls.Data.FilterExpressionException' occurred in Telerik.WinControls.dll
    An unhandled exception of type 
    'Telerik.WinControls.Data.FilterExpressionException' occurred in Telerik.WinControls.dll
    Additional information: Invalid filter expression.

    Screen exception:
    ************** Exception Text **************
    Telerik.WinControls.Data.FilterExpressionException: Invalid filter expression. ---> Telerik.Data.Expressions.InvalidExpressionException: The expression contains object 'column4' that is not defined in the current context.
       at Telerik.Data.Expressions.NameNode.Eval(Object row, Object context)
       at Telerik.Data.Expressions.LikeNode.Eval(Object row, Object context)
       at Telerik.Data.Expressions.Operator.AndFunc(Operand lhs, Operand rhs, OperatorContext context)
       at Telerik.Data.Expressions.BinaryOpNode.Eval(Object row, Object context)
       at Telerik.WinControls.Data.RadCollectionView`1.PerformExpressionFilter(TDataItem item)
       --- End of inner exception stack trace ---
       at Telerik.WinControls.Data.RadCollectionView`1.PerformExpressionFilter(TDataItem item)
       at Telerik.WinControls.Data.RadCollectionView`1.PassesFilter(TDataItem item)
       at Telerik.Collections.Generic.HybridIndex`1.PerformWithQuickSort()
       at Telerik.Collections.Generic.HybridIndex`1.Perform()
       at Telerik.Collections.Generic.HybridIndex`1.get_Items()
       at Telerik.Collections.Generic.Index`1.get_Count()
       at Telerik.WinControls.Data.GroupBuilder`1.get_Groups()
       at Telerik.WinControls.Data.RadDataView`1.get_Groups()
       at Telerik.WinControls.UI.GridViewTemplate.get_Groups()
       at Telerik.WinControls.UI.GridViewTemplate.RefreshSummaryRowsInGroup(NotifyCollectionChangedEventArgs e)
       at Telerik.WinControls.UI.GridViewTemplate.RefreshAggregates(NotifyCollectionChangedEventArgs e)
       at Telerik.WinControls.UI.GridViewTemplate.OnViewChanged(Object sender, DataViewChangedEventArgs e)
       at Telerik.WinControls.UI.GridViewTemplate.CollectionView_CollectionChanged(Object sender, NotifyCollectionChangedEventArgs e)
       at Telerik.WinControls.Data.RadCollectionView`1.OnCollectionChanged(NotifyCollectionChangedEventArgs args)
       at Telerik.WinControls.Data.RadDataView`1.RebuildData(Boolean notify)
       at Telerik.WinControls.Data.RadDataView`1.RefreshOverride()
       at Telerik.WinControls.Data.RadDataView`1.OnNotifyPropertyChanged(PropertyChangedEventArgs e)
       at Telerik.WinControls.Data.RadCollectionView`1.set_FilterExpression(String value)
       at Telerik.WinControls.UI.GridViewFilterDescriptorCollection.ApplyFilter()
       at Telerik.WinControls.UI.GridViewFilterDescriptorCollection.OnCollectionChanged(NotifyCollectionChangedEventArgs args)
       at Telerik.Collections.Generic.NotifyCollection`1.InsertItem(Int32 index, T item)
       at Telerik.WinControls.UI.GridViewFilterDescriptorCollection.InsertItem(Int32 index, FilterDescriptor item)
       at System.Collections.ObjectModel.Collection`1.Add(T item)
       at Telerik.WinControls.UI.GridViewDataColumn.SetFilterDescriptor(FilterDescriptor value)
       at Telerik.WinControls.UI.GridViewFilteringRowInfo.SetFilterDesriptor(GridViewDataColumn dataColumn, FilterDescriptor descriptor)
       at Telerik.WinControls.UI.GridViewFilteringRowInfo.set_Item(GridViewColumn column, Object value)
       at Telerik.WinControls.UI.GridDataCellElement.set_Value(Object value)
       at Telerik.WinControls.UI.GridFilterCellElement.set_Value(Object value)
       at Telerik.WinControls.UI.GridFilterCellElement.Editor_ValueChanged(Object sender, EventArgs e)
       at Telerik.WinControls.UI.BaseInputEditor.OnValueChanged()
       at Telerik.WinControls.UI.BaseGridEditor.OnValueChanged()
       at Telerik.WinControls.UI.RadTextBoxEditor.TextBoxItem_TextChanged(Object sender, EventArgs e)
       at System.EventHandler.Invoke(Object sender, EventArgs e)
       at Telerik.WinControls.RadItem.OnTextChanged(EventArgs e)
       at Telerik.WinControls.RadItem.OnPropertyChanged(RadPropertyChangedEventArgs e)
       at Telerik.WinControls.RadHostItem.OnPropertyChanged(RadPropertyChangedEventArgs e)
       at Telerik.WinControls.UI.RadTextBoxItem.OnPropertyChanged(RadPropertyChangedEventArgs e)
       at Telerik.WinControls.RadObject.RaisePropertyNotifications(RadPropertyValue propVal, Object oldValue, Object newValue, ValueSource oldSource)
       at Telerik.WinControls.RadObject.SetValueCore(RadPropertyValue propVal, Object propModifier, Object newValue, ValueSource source)
       at Telerik.WinControls.RadElement.SetValueCore(RadPropertyValue propVal, Object propModifier, Object newValue, ValueSource source)
       at Telerik.WinControls.UI.RadTextBoxItem.TextBoxControl_TextChanged(Object sender, EventArgs e)
       at System.Windows.Forms.Control.OnTextChanged(EventArgs e)
       at System.Windows.Forms.TextBoxBase.OnTextChanged(EventArgs e)
       at System.Windows.Forms.TextBoxBase.WmReflectCommand(Message& m)
       at System.Windows.Forms.TextBoxBase.WndProc(Message& m)
       at System.Windows.Forms.TextBox.WndProc(Message& m)
       at Telerik.WinControls.UI.HostedTextBoxBase.WndProc(Message& message)
       at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
       at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
       at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
  2. Answer
    Ivan Petrov
    Admin
    Ivan Petrov avatar
    717 posts

    Posted 14 Jun 2013 Link to this post

    Hi Diminik,

    Thank you for writing.

    We are aware of this issue and have it logged in our Public Issue Tracking System - PITS. You can see the entry here - PITS Issue. The issue has been addressed in our latest version which is 2013 Q2. The 2013 Q2 release is publicly available from June 12 2013 and you can download it and give it a try.

    I hope this will help. Should you have further questions, I would be glad to help.

    Regards,
    Ivan Petrov
    Telerik
    RadChart for WinForms is obsolete. Now what?
  3. Dominik
    Dominik avatar
    82 posts
    Member since:
    Dec 2012

    Posted 20 Jun 2013 Link to this post

    Thank you for the information. Indeed, the latest version does not have this bug. :)
Back to Top