I have looked at the other threads relating to this issue and they either dead end or reference methods/properties that are no longer available.
I populated my RadGridView via DataSet
I also populate numerous comboboxes with that same Dataset.
I desire to select to select a combobox, choose an item within the combobox and on selectedindex changed filter the RadGridView accordingly.
I also want to be able to select as many comboboxes as i'd like to continuously filter down the RadGridView.
I cannot seem to find valid code for setting the filter expression programatically.
Please advise.
18 Answers, 1 is accepted
Thank you for contacting us. In order to achieve the desired behavior you should handle the SelectedIndexChanged event and set a new filter expression to the column that corresponds to the current RadComboBox. If you have encountered any issues assigning filter expressions please, refer to the this article. It provides examples how to set filter expressions programmatically and also how to assign filters for multiple columns. Please, note that in order to apply a filter the EnableFiltering property of RadGridView should be set to true. Another important point in your case is that you should bind each RadComboBox to a different BindingSource. I hope this is helpful. If you have further question, do not hesitate to contact me back.
Best wishes,
Boryana
the Telerik team
Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
Thank you for your reply I had found the article that you reference in your reply and I am in the process of implementing.
I did take your advice and I actually populate the combobox based on the contents of the radgridview:
Dim OrderNumbers As String = String.Empty
For Each rowinfo As GridViewRowInfo In dgvDetails.Rows
With cboOrderNumbers
Dim newValue As String = Convert.ToInt16(rowinfo.Cells(10).Value).ToString
If Not OrderNumbers.Contains(newValue) Then
.Items.Add(New RadComboBoxItem(newValue))
OrderNumbers += newValue + ","
End If
'if we don't do this then the value is null
rowinfo.Cells(0).Value = False
End With
Next
I set .EnableFiltering to False because I didn't want the filter row to be visible but of course then the programatic filtering didn't work.
Is there a way to .EnableFiltering and keep the Filter Row not visible?
Thank you in advance for your response.
Bob
Please, add the following snippet to your code:
Me.radGridView1.EnableFiltering = True |
Me.radGridView1.MasterGridViewTemplate.ShowFilteringRow = False |
I hope this helps. If you have further questions, please contact me back.
All the best,
Boryana
the Telerik team
Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
That is what I was looking for. I'm still new to the Telerik controls so I don't always no where to find what I'm looking for.
It does seem however that I can do just about anything I want if I can find it - or you guys tell me where it is :)
One final question/observation...
Is this the correct and/or most efficient way to clear a specific filter?
filter.Predicates.Clear()
filter.Parameters.Clear()
Me.RagGridView1.Columns(columnName).Filter = filter
Is this the correct and/or most efficient way to clear "ALL" filters.
Me.RadGridView1.MasterGridViewTemplate.FilterExpressions.Clear()
I believe that the best way to clear the filter expression of RadGridView is:
Me.radGridView1.MasterGridViewTemplate.FilterExpressions.Clear() |
Kind regards,
Boryana
the Telerik team
Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
Your responses to this question have been very helpful to me despite it not being my original post, but I have run into another roadblock.
I am finding that (and correct me if I'm wrong) the GridKnownFunction.EqualTo function cannot be used to compare two strings.
In my case I have a grid with many columns of different types. On one of the columns which I have explicitly set the columns datatype to : typeof(string), and which contains values coming from a query typed as VARCHAR(10), I have an EqualTo filter. I can take a value from one of the cells in that column, paste it into the EqualTo filter box and I get no results. I change it to 'BeginsWith' and I get no results. I change it to 'EndsWith' and I get what would be expected. In this example, below are the values being used and the reasons it won't work for me if this is the only way:
A value from that column: " 11" (without the quotes)
With that value in the filter bar and EqualTo set as the function, I get 0 records.
With that value in the filter bar and StartsWith set as the function, I get 0 records.
With that value in the filter bar and EndsWith set as the function, I get something like 50 records. But it isn't strings that end with " 11" but rather strings that end with "11". I get the following results:
11
11
20011
67411
67511
...
70011
etc.
That seems to tell me that the preceding spaces in the filter string are ignored but preceding spaces in the rows being compared to the filter are not; that is the only behavior that can explain why it would match EndsWith but not BeginsWith or EqualTo. Is there a way to make the filtering NOT ignore those preceeding spaces? I REALLY want to set the filter to EqualTo, pass in " 11" and get the rows that have that value EqualTo " 11".
Work-around accomplished, but if there is a way to disable this behavior in the tool myself that would be nice.
Thank you for the detailed explanation of your issue. Unfortunately, what you are experiencing is the default behavior of RadGridView. Your suggestion that there should not be any assumed trimming seems convincing and is highly appreciated by our team. Your case made us reconsider the behavior of RadGridView for future releases. Thank you once again for your feedback. It comes out that at the moment the workaround that you have found yourself is the only one we can suggest. If you encounter any further issues, please contact me back. I will be glad to assist you.
Sincerely yours,
Boryana
the Telerik team
Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
Thank you for the response verifying that this is indeed the default behavior and that there is no provided option within the component for a work-around. I would recommend, but I'm sure having made modification like this to components in the past you guys would do this anyway, that you leave the current functionality as the default so as not to break compatibility and provide a property on the Telerik.WinControls.Data.FilterExpression (if that's where the stripping is occurring) to tell it not to strip spaces. I can see times where it may be desirable, but most certainly for existing implementations.
Telerik.WinControls.Data.FilterExpression filter = new Telerik.WinControls.Data.FilterExpression(); |
filter.Predicates.Add(Telerik.WinControls.Data.FilterExpression.BinaryOperation.AND, GridKnownFunction.EqualTo, GridFilterCellElement.ParameterName); |
filter.Parameters.Add(GridFilterCellElement.ParameterName, radGridView1.CurrentRow.Cells["ColumnName"].Value.ToString()); |
filter.StripLeadingSpaces = false; |
radGridView2.Columns["ColumnToFilter"].Filter = filter; |
That would be sweet.
Thank you for listening and for the great tools; for every question or problem I post here, I have 100 success stories of your tools saving time and/or enhancing the look and feel of my applications.
-Rick
Rick Petersen's blog post on radGridView filtering with strings
Our team highly appreciates your feedback and we are happy to see that in most cases RadGridView covers your expectations. Your blog post states both the advantages of RadGridView and its week sides which marks the direction for future improvement on our side. Once again thank you very much for evaluating our controls.
I have updated your Telerik points for your blog post. If there is a way we can assist you, please let us know.
Best wishes,
Boryana
the Telerik team
Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
I am using RadGrid control on my C# windows form. I want to add filter for column so that my grid should look like as following image. Please guide me how to achive this .
Thanks,
Shailesh
Thank you for writing.
The screenshot you provided suggests that would like to enable the basic filtering functionality of RadGridView. You will be able to find more information on the topic here: http://www.telerik.com/help/winforms/gridview-filtering-basic-filtering.html.
In case I did not understand your question correctly, I kindly ask to you open a separate thread and provide further details there.
Regards,
Boryana
the Telerik team
Hello
May I Have Just "Contains" for Filtering Without displaying filter box (Followed By this link)
https://docs.telerik.com/devtools/winforms/controls/gridview/filtering/basic-filtering
I`d like to Reduce the Filter Menu Options or Not showing filter box at all.
when ever End User start to Type text ,Displaying Search Text Box and then search with operator "Contains" for every Column.
thank you
Hello again
Excuse me Can I Have ServerSide Filtering and sorting in radgridview in winform. Do You Have a sample?
Thank You
Hello, Aseman,
The "Contains" filter operator is relevant for the text columns. For the other column types different filter operators are displayed.
The following KB article demonstrates how to specify default filter operator and thus you can set the "Contains" filter operator for the text columns: https://docs.telerik.com/devtools/winforms/knowledge-base/set-default-filter-operators-in-gridview
The RadGridView.ContextMenuOpening event is fired when the filter popup is going to be opened. This is the appropriate place to hide some of the menu items that you don't want to be displayed:
public RadForm1()
{
InitializeComponent();
this.radGridView1.EnableFiltering = true;
this.radGridView1.ContextMenuOpening+=radGridView1_ContextMenuOpening;
}
private void radGridView1_ContextMenuOpening(object sender, ContextMenuOpeningEventArgs e)
{
if (e.ContextMenuProvider is GridFilterCellElement)
{
e.ContextMenu.Items[0].Visibility = ElementVisibility.Collapsed;
}
}
If the applied default filter operator is the only one that you are going to use and want to hide the filter button, ou can subscribe to the ViewCellFormatting event and use the following code snippet:
private void radGridView1_ViewCellFormatting(object sender, CellFormattingEventArgs e)
{
GridFilterCellElement filterCell = e.CellElement as GridFilterCellElement;
if (filterCell!=null)
{
filterCell.FilterButton.Visibility = ElementVisibility.Collapsed;
}
}
Note that all operations like filtering, paging, grouping etc. that RadGridView offers, are client-side based since RadGridView is designed to work with its data applied via the DataSource property. Server-side filtering may be implemented with RadVirtualGrid as it loads data on demand. You can refer the Demo application >> VirtualGrid >> First look example where in the FilterChanged event the new relevant data is extracted from the external data source and then filled in the virtual grid via the CellValueNeeded event.
I hope this information helps.
Regards,
Dess | Tech Support Engineer, Sr.
Progress Telerik
thank you Dear Dess
and how can I change the Size of context Menu? Because I have just One Record "Contains" in it.
Hello Aseman,
Dess is out of the office today so I will be handling this case.
You can set the size of the context menu for the filter pop up in the ContextMenuOpening event:
private void radGridView1_ContextMenuOpening(object sender, ContextMenuOpeningEventArgs e)
{
if (e.ContextMenuProvider is GridFilterCellElement)
{
e.ContextMenu.MinimumSize = new Size(100, 0);
}
}
I hope this helps. Should you have any other questions do not hesitate to ask.
Regards,
Nadya
Progress Telerik