I have this piece of code very similar to the one in the demos but I allways get an empty string from FilterDescriptors.Expression
this.Confecciones.AllowFiltering = true;
this.ConfeccionesGV.FilterChanged += Confecciones_FilterChanged;
void ConfeccionesGV_FilterChanged(object sender, VirtualGridEventArgs e)
{
Filter();
}
private void Filter()
{
string filterExpression = this.ConfeccionesGV.FilterDescriptors.Expression;
if (!string.IsNullOrEmpty(filterExpression))
MessageBox.Show(filterExpression);
}
13 Answers, 1 is accepted
Thank you for writing.
You need to specify the FieldName in the CellValueNeeded event handler. This way the expression will be set properly:
if
(e.RowIndex < 0)
{
e.FieldName =
"Col"
+ e.ColumnIndex;
}
Please let me know if there is something else I can help you with.
Dimitar
Telerik
I have used the following code with the latest version and the results are correct on my side. What I need to change in order to reproduce this:
public
RadForm1()
{
InitializeComponent();
radVirtualGrid1.CellValueNeeded += RadVirtualGrid1_CellValueNeeded;
radVirtualGrid1.ColumnCount = 10;
radVirtualGrid1.RowCount = 100;
radVirtualGrid1.FilterChanged += RadVirtualGrid1_FilterChanged;
}
private
void
RadVirtualGrid1_FilterChanged(
object
sender, Telerik.WinControls.UI.VirtualGridEventArgs e)
{
Console.WriteLine(radVirtualGrid1.FilterDescriptors[0].Expression);
Console.WriteLine(radVirtualGrid1.FilterDescriptors[0].PropertyName);
}
private
void
RadVirtualGrid1_CellValueNeeded(
object
sender, Telerik.WinControls.UI.VirtualGridCellValueNeededEventArgs e)
{
e.Value =
"test"
;
e.FieldName =
"Field"
+ e.RowIndex +
" "
+ e.ColumnIndex;
}
I am looking forward to your reply.
Dimitar
Telerik by Progress
Hi Dimitar,
It was my mistake. I had field name/value setting lines inside an if condition like below. Now I moved it outside the if block.
if (e.RowIndex == RadVirtualGrid.HeaderRowIndex) // header
{
e.FieldName = GetFieldName(headerItem);
e.Value = headerItem.DisplayName;
Thanks,
Saji.
I am glad that you have found a solution for this case. Do not hesitate to contact us if you have other questions.
Dimitar
Telerik by Progress
Hello.
I need help.
How can delete filter in standart filterdescriptions collection?
For example. Grid contain columns with int values, but in filters have operators like or notlike. We recieve error if use this filters
You can use the Remove, RemoveAt or Clear methods:
radVirtualGrid1.FilterDescriptors.RemoveAt(0);
radVirtualGrid1.FilterDescriptors.Clear();
I hope this will be useful. Let me know if you have additional questions.
Regards,
Dimitar
Telerik by Progress
Hi, Dimitar.
tis functions use to clear filters, but no context menu with operation types.
May be to use
this.VirtualGrid.MasterViewInfo.SetColumnDataType(new Type[] {typeof(String), typeof(decimal)});
Yes, setting the data type will give you a correct set of items in the filter drop down. You can set this using a column index as well:
this
.radVirtualGrid1.MasterViewInfo.SetColumnDataType(1,
typeof
(DateTime) );
Please let me know if there is something else I can help you with.
Regards,
Dimitar
Telerik by Progress
Hi, Dimitar.
No, thanks. Thanks for help.
Best regards.
var newDescList = new FilterDescriptorCollection();
foreach(var x in grid.FilterDescriptors)
{
var newDesc = new CoreVirtualGridFilterDescriptor(x.PropertyName, youroperator, x.Value)
newDescList.Add(newDesc);
}
// now use newDescList for your filtering purpose.
Hello Dimitar
Excuse me Can you explain me all the conditions in Cellvalur Needed Event ? like "if (e.RowIndex < 0) " or " if (e.RowIndex == RadVirtualGrid.HeaderRowIndex)"
thanks
The CellValueNeeded event in RadVirtualGrid is fired whenever a cell value is required by the grid. It is necessary to specify the Value argument considering the RowIndex/ColumnIndex. Additional information how to populate RadVirtualGrid with data is available here: https://docs.telerik.com/devtools/winforms/controls/virtualgrid/working-with-data/virtualgrid-populating-with-data
All data rows have index greater than or equal to 0. The system rows have index less than 0. The following help article illustrates the available system rows in RadVirtualGrid: https://docs.telerik.com/devtools/winforms/controls/virtualgrid/rows/system-rows
Here are the respective index of the row:
- HeaderRowIndex = -1
- NewRowIndex = -2
- FilterRowIndex = -3
I hope this information helps.
Regards,
Dess | Tech Support Engineer, Sr.
Progress Telerik