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:
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:
Screen exception:
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)