21 Answers, 1 is accepted
Thank you for writing.
Please refer to the following code snippet, which demonstrates how to set the default filter operator for the first column in the grid:
radGridView1.Columns[0].FilterDescriptor =
new
Telerik.WinControls.Data.FilterDescriptor(
null
, Telerik.WinControls.Data.FilterOperator.StartsWith,
null
);
I hope that you find this information useful. Should you have any other questions, do not hesitate to contact us.
Greetings,
Stefan
the Telerik team
SP1 of Q3’11 of RadControls for WinForms is available for download (see what's new).
Your code works. Thanks
I am glad that I could help. If there is anything else we can assist you with, do not hesitate to contact us.
All the best,
Stefan
the Telerik team
SP1 of Q3’11 of RadControls for WinForms is available for download (see what's new).
Hi,
This doesn't seem to work with nullable columns. In my case I have a decimal? field and if when I'm trying to do what you suggested here, the non-null values are filtered out. Any ideas?
Thanks.
Thank you for writing.
Please note that the StartsWith operator is not commonly used with GridViewDecimalColumn and that is why it cannot be added from the UI. However, following the described in the thread approach it can be added programmatically.
The null values are filtered out and this is behavior in this kind of setup. With filtering, you would be able to add custom logic for the null values: http://docs.telerik.com/devtools/winforms/gridview/filtering/custom-filtering.
I hope this helps. Should you have further questions please do not hesitate to write back.
Regards,
Hristo Merdjanov
Telerik by Progress
Maybe I didn't make myself clear enough in my previous post. I'll try a better description of my issue.
I have 2 fields in a grid, one is decimal, one is decimal?. For both I’m setting the filter option in the design view to “Equal” - img1.
When I start the application, the decimal ones has the filter ok, but the decimal? filter is changed to “No filter” - img2
If I try the workaround from here, it works, but not as I would expect. The filter is applied for the null value and all my decimal? values that are not null are hidden. What I need is just to have the default filter option set to “Equal”, with no filter applied at all.
Thanks,
Dumi.
Thank you for writing back.
The empty text you have will be filtered out when you apply the IsEqualTo operator to the decimal column and this is expected. As stated in my previous post you need to enable custom filtering and handle the filter operation with respect to the null values and leave them visible: http://docs.telerik.com/devtools/winforms/gridview/filtering/custom-filtering.
I hope this helps. Should you have further questions please do not hesitate to write back.
Regards,
Hristo Merdjanov
Telerik by Progress
I understand what you're saying, I'm already using custom filtering in some of my grids. But what I don't understand is the different behavior of the grid view based on the data type for a column. I don't want to apply a filter, I just want the default filter option to be IsEqualTo. Why does it work for decimal, but not for decimal? ? In my opinion this is an issue of the grid...
Thanks,
Dumi.
The default filter operators are determined according to the data type of the column. Since you are having a nullable decimal field, the engine assigns the FilterOperator.None as default.
As discussed previously in the thread you can add an empty filter having the IsEqualTo operator. In case you keep experiencing issues please open up a support ticket and send us your project so that we can further investigate it.
I hope this helps. Should you have further questions please do not hesitate to write back.
Regards,
Hristo Merdjanov
Telerik by Progress
I was looking for the same behavior Dumi was above. I didn't want to apply a filter but rather I just wanted the default operator to be "IsEqualTo". I simply set the .DataType of the nullable column in question to typeof(int) which didn't affect the data in the row or the native filtering capabilities. But then the default operator was "IsEqualTo" without having to do anything else. To set the data type of the column do this:
myRadGridView.Columns[
"NameOfColumn"
].DataType =
typeof
(
int
);
Thank you for sharing your solution with the community. I see no issues with it in the discussed context.
I hope this helps. Please let me know if you have other questions.
Regards,
Hristo
Progress Telerik
Hi Jared,
Perfect solution! I can get over this issue now ;)
Thanks a lot!
Hi,
I also have problem with filters in columns which types nullable. When i set filter operator like shown below:
grid.Columns[0].FilterDescriptor = new Telerik.WinControls.Data.FilterDescriptor(null, Telerik.WinControls.Data.FilterOperator.IsEqualTo, null);
the filter operator is set properly but the filter icon is shine.
How can I set the filter operator without light on the icon?
All the best
Hi, Zygmunt,
When a FilterDescriptor is applied to a column, it is desired behavior to highlight the filter button. This way the user can see a clear indication by which columns the grid is filtered. Why do you want to hide this indication from the user? Wouldn't it be confusing?
Meanwhile, you can customize the GridFilterCellElement by using the ViewCellFormatting event. Once you cast the CellElement to GridFilterCellElement, you will have access to the FilterButton and you can apply any image you want in order to keep identical design when there is an applied filter and there is not.
@Zygmunt,
Usually, when you add a FilterDescriptor programmatically, you are expected to do it this way: https://docs.telerik.com/devtools/winforms/controls/gridview/filtering/setting-filters-programmatically-(simple-descriptors)#using-simple-filterdescriptor
The IsFilterEditor flag controls the highlight indication for the filter button. By default, you are expected to set it to true in order to toggle the filter button. If you are setting it to false, you may not have the filter button highlighted.
var filter = new FilterDescriptor(null, FilterOperator.IsEqualTo, null);
filter.IsFilterEditor = false;
gridView.Columns["OcrDataWystawienia"].FilterDescriptor = filter;
Hello, Zygmunt,
According to the provided picture in your post here, it seems that you are using the ControlDefault theme. In this theme, the filtering icons are represented via RadSvgImages. If I understand you correctly you want to remove the highlight filtering icon although there is a filter applied and display the default icon. To achieve this you can use the ViewCellFormatting event and change the displayed icon:
public RadForm1()
{
InitializeComponent();
var filter = new FilterDescriptor(null, FilterOperator.IsEqualTo, null);
filter.IsFilterEditor = false;
radGridView1.Columns["column1"].FilterDescriptor = filter;
radGridView1.ViewCellFormatting += RadGridView1_ViewCellFormatting;
}
private void RadGridView1_ViewCellFormatting(object sender, CellFormattingEventArgs e)
{
GridFilterCellElement headerCell = e.CellElement as GridFilterCellElement;
if (headerCell != null && headerCell.ColumnInfo.Name == "column1")
{
RadSvgImage svg = RadSvgImage.FromFile(@"..//..//xml.xml");
headerCell.FilterButton.SvgImage = svg;
}
}
Here is the XML file with the RadSvgImage for your reference:
<?xml version="1.0" encoding="utf-8"?>
<svg width="19" height="18" viewBox="0, 0, 19, 18" xml="http://www.w3.org/XML/1998/namespace" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:xml="http://www.w3.org/XML/1998/namespace" version="1.1">
<defs>
<style>
.cls-1, .cls-2 {
fill-rule: evenodd;
}
.cls-1 {
fill: url(#linear-gradient);
}
.cls-2 {
fill: url(#linear-gradient-2);
}
</style>
<linearGradient x1="4" y1="9" x2="15" y2="9" gradientUnits="userSpaceOnUse" id="linear-gradient">
<stop offset="0%" stop-color="#5B83BA" />
<stop offset="15%" stop-color="#557BB1" />
<stop offset="41%" stop-color="#436697" />
<stop offset="74%" stop-color="#28446E" />
<stop offset="100%" stop-color="#0E2448" />
</linearGradient>
<linearGradient x1="6" y1="8.5" x2="13" y2="8.5" gradientUnits="userSpaceOnUse" id="linear-gradient-2">
<stop offset="0%" stop-color="#F7FCFF" />
<stop offset="35%" stop-color="#DCEBFB" />
<stop offset="75%" stop-color="#C4DBF6" />
<stop offset="100%" stop-color="#BBD5F5" />
</linearGradient>
</defs>
<g id="Layer_3" data-name="Layer 3">
<polygon points="15,4 4,4 4,6 8,9 8,13 9,14 11,14 11,9 15,6 15,4" fill-rule="evenodd" class="cls-1" style="fill:url(#linear-gradient);" />
<polygon points="13,5 6,5 6,6 9,8 9,12 10,12 10,8 13,6 13,5" fill-rule="evenodd" class="cls-2" style="fill:url(#linear-gradient-2);" />
</g>
</svg>
Thus, although there is a FilterDescriptor added for the column1 the filtering icon will not be highlighted:
I hope this helps. If you have other questions please let me know.
Regards,
Nadya
Progress Telerik
Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.
I use default theme but when I set filter operator for columns with nullable types using code below:
var filter = new FilterDescriptor(null, FilterOperator.IsEqualTo, null);
filter.IsFilterEditor = false;
gridView.Columns["OcrDataWystawienia"].FilterDescriptor = filter;
the filter icon is like on this picture
but I would like the icon to look like below
Hello, Zygmunt,
According to the provided picture, it seems that you enabled both the Excel-like filtering functionality in RadGridView as well as the basic filtering. Could you please specify which filtering mechanism you intend to use in RadGridView? Mixing them both is not a good approach.
For your reference, I am providing my sample project where basic filtering is used. You can see that there is a filter applied to the first collection but the icon is not highlighted as shown in my previous reply. You can achieve a similar result when using Excel-like filtering if you prefer to use it.
Please, keep in mind that when FilterDescriptor is applied to a column, it is desired behavior to highlight the filter button. This way the user can see a clear indication by which columns the grid is filtered.
I hope this helps. Should you have further questions please let me know.
Regards,
Nadya
Progress Telerik
Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.
I would like to use basic filtering. I have in my grid some columns which can take null vaules. Defaultly the filter type for nullable columns are none but I would like to change it programically to equal at program start.
When I assign the filter descriptor to the column the icon light on but I would like the column look like others on start.
Hi, Zygmunt,
Thank you for clarifying that you want to use the basic filtering functionality.
Did you give the project sent in my previous reply a try? I have modified the icon in the ViewCellFormatting event to show a non-highlighted icon (the default one) when FilterOperator.IsEqualTo is applied:
var filter = new FilterDescriptor(null, FilterOperator.IsEqualTo, null);
filter.IsFilterEditor = false;
radGridView1.Columns["column1"].FilterDescriptor = filter;
Please let me know how this works for you.
Regards,
Nadya
Progress Telerik
Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.
Hi, Zygmunt,
SVG images support was introduced in R2 2020. If you are using an older version you shouldn't be able to access the RadSvgImage class.
In this case, you can use the FilterButton.Image property instead of SvgImage and assign any custom image that is suitable for you in the ViewCellFormatting event:
private void RadGridView1_ViewCellFormatting(object sender, CellFormattingEventArgs e)
{
GridFilterCellElement headerCell = e.CellElement as GridFilterCellElement;
if (headerCell != null && headerCell.ColumnInfo.Name == "column1")
{
headerCell.FilterButton.Image = myimage;
}
}
I hope this helps.
Regards,
Nadya
Progress Telerik
Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.
Hi,
The solution is not in 100% satisfactory for me. I checked that when I changed manually the filter operator from "None" to "IsEqualTo" the value of FilterDescriptor property was null. I understand that means that filter operator is not storaged in FilterDescriptor property so I ask to show me how I could do it without necessity of setting the FilterDescriptor.
Hello, Zygmunt,
If you want to change the default filter operator for a certain column without applying a FilterDescriptor to this column and without indicating any filter is applied, I would recommend you to have a look at the following KB article which is quite useful on this topic:
https://docs.telerik.com/devtools/winforms/knowledge-base/set-default-filter-operators-in-gridview
Please give it a try and see how it would work for your custom scenario.
Regards,
Dess | Tech Support Engineer, Principal
Progress Telerik
Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.