CustomFiltering and default FilterRow together

16 posts, 0 answers
  1. Raffaele
    Raffaele avatar
    1 posts
    Member since:
    Aug 2013

    Posted 14 Mar 2014 Link to this post

    Hi everyone,

    my trial period is almost over and I really like Telerik components.
    There is just one little thing that I have issues with.

    Let CustomFiltering and the default Filter via FilterRow work together.
    I read examples about achieving this goal under C#, but I can't figure out how to make this work under VB.

    Can anyone please help me?

    Thank you in advance!
    Bye
  2. Dimitar
    Admin
    Dimitar avatar
    2818 posts

    Posted 18 Mar 2014 Link to this post

    Hello Raffaele,

    Your question has already been answered in the other thread you've opened. However I am copying the answer here in order for the community to benefit from it:

    In the general case the you can specify if particular row should be visible in the CustomFiltering event. For rows that should be handled by the default filtering you should set the Handled property of the GridViewCustomFilteringEventArgs object to false. For example:
    Private Sub radGridView1_CustomFiltering(sender As Object, e As Telerik.WinControls.UI.GridViewCustomFilteringEventArgs)
        Dim value As String = DirectCast(e.Row.Cells(1).Value, String)
        If Not value.Contains("in") Then
            e.Visible = False
        ElseIf radGridView1.Columns(1).FilterDescriptor IsNot Nothing Then
            e.Handled = False
        End If
    End Sub

    I hope this helps.

    Regards,
    Dimitar
    Telerik
     

    DevCraft Q1'14 is here! Watch the online conference to see how this release solves your top-5 .NET challenges. Watch on demand now.

     
  3. Fabrizio
    Fabrizio avatar
    20 posts
    Member since:
    May 2019

    Posted 24 Jun in reply to Dimitar Link to this post

    Hi Dimitar

    I have a question about the customFiltering.

    I have a bound Gridview and the MasterTemplate has two child template. I created GridViewRelation, everything works perfectly.

    Now I would like to use a CustomFiltering. I initialized these properties of my GridView :

        SchoolStudentDGV.EnableHotTracking = true;
        SchoolStudentDGV.ShowFilteringRow = false;
        SchoolStudentDGV.EnableFiltering= true;
        SchoolStudentDGV.EnableCustomFiltering = true;

    I handled the "CustomFiltering" event and the "TextChanged" of the filter TextBox.

    In the TextChanged method, I have this code : this.SchoolStudentDGV.MasterTemplate.Refresh();

    In the CustomFiltering method, I have this :

                if (string.IsNullOrEmpty(this.filterTextBox.Text))
                {
                    this.SchoolStudentDGV.BeginUpdate();
                    e.Visible = true;
                    e.Row.IsVisible = true;

                    for (int i = 0; i < e.Row.ViewTemplate.ColumnCount; i++)
                    {
                        e.Row.Cells[i].Style.Reset();
                    }

                    this.SchoolStudentDGV.EndUpdate(false);
                    return;
                }

                this.SchoolStudentDGV.BeginUpdate();
                e.Visible = false;
                e.Row.IsVisible = false;

                for (int i = 0; i < e.Row.ViewTemplate.ColumnCount; i++)
                {
                    string text = e.Row.Cells[i].Value?.ToString() ?? "";

                    if (e.Row.Cells[i].ColumnInfo.IsVisible &&
                        text.IndexOf(this.filterTextBox.Text, 0, StringComparison.InvariantCultureIgnoreCase) >= 0)
                    {
                        e.Visible = true;
                        e.Row.IsVisible = true;
                        e.Row.Cells[i].Style.CustomizeFill = true;
                        e.Row.Cells[i].Style.DrawFill = true;
                        e.Row.Cells[i].Style.BackColor = Color.FromArgb(201, 252, 254);
                    }
                    else
                    {
                        e.Row.Cells[i].Style.Reset();
                    }
                }

                this.SchoolStudentDGV.EndUpdate(false);

    It works, rows of the MasterTemplate are filtered but I would like to apply the same filter to children template. Can you tell me if is it possible ?

     

    Thank you

  4. Dimitar
    Admin
    Dimitar avatar
    2818 posts

    Posted 24 Jun Link to this post

    Hello Raffaele,

    You need to enable the custom filtering of the child templates as well:
    GridViewTemplate template = new GridViewTemplate();
    template.EnableCustomFiltering = true;
    template.EnableFiltering = true;
    template.ShowFilteringRow = false;

    I hope this helps. Should you have any other questions, do not hesitate to ask.
     
    Regards,
    Dimitar
    Progress Telerik
    Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
  5. Fabrizio
    Fabrizio avatar
    20 posts
    Member since:
    May 2019

    Posted 24 Jun in reply to Dimitar Link to this post

    Hi,

    I did that however if the parent row doesn't match to the filter, is not visible and all children rows of this parent row are hidden and the filter is not applied to those children row.

    Thanks

  6. Dimitar
    Admin
    Dimitar avatar
    2818 posts

    Posted 25 Jun Link to this post

    Hello Fabrizio,

    You will need to check if the child rows match the filter criteria manually as well, and leave the parent row visible. For example you can add the following code to the end of the CustomFiltering event handler:
    if (e.Row.HierarchyLevel == 0)
    {
        foreach (var childRow in e.Row.ChildRows)
        {
            for (int i = 0; i < childRow.ViewTemplate.ColumnCount; i++)
            {
                string text = childRow.Cells[i].Value?.ToString() ?? "";
     
                if (childRow.Cells[i].ColumnInfo.IsVisible &&
                    text.IndexOf(this.radTextBox1.Text, 0, StringComparison.InvariantCultureIgnoreCase) >= 0)
                {
                    e.Visible = true;
                    e.Row.IsVisible = true;
                }
                
            }
        }
    }

    Should you have any other questions, do not hesitate to ask.
     
    Regards,
    Dimitar
    Progress Telerik
    Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
  7. Fabrizio
    Fabrizio avatar
    20 posts
    Member since:
    May 2019

    Posted 28 Jun in reply to Dimitar Link to this post

    Good morning Dimitar

    I will test.

    I have another question about a radgridview bound. I have two GridViewComboBoxColumn and I can add new row. I handle the "CellEditorInitialized" event.

    private void CoteDGV_CellEditorInitialized(object sender, GridViewCellEventArgs e)

    {
                RadDropDownListEditor editor = e.ActiveEditor as RadDropDownListEditor;
                RadDropDownListEditorElement editorElement = editor?.EditorElement as RadDropDownListEditorElement;
                if (editorElement == null)
                    return;

                GridViewComboBoxColumn cbc = e.Column as GridViewComboBoxColumn;

                switch (e.Column.Name)
                {
                    case "PeriodeColumn":
                        editorElement.ListElement.SelectedIndexChanged -= CoteDGVDropdownEditor_SelectedIndexChanged;
                        editorElement.DataSource = _allControlsToAddCote
                            .Select(x => x.Period)
                            .Distinct()
                            .OrderBy(x => x);
                        editorElement.ListElement.SelectedIndexChanged += CoteDGVDropdownEditor_SelectedIndexChanged;
                        break;

                    case "DisciplineColumn":
                        (e.Column as GridViewComboBoxColumn).DataSource = _disciplinesFound;
                        editorElement.ListElement.SelectedIndexChanged -= CoteDGVDropdownEditor_SelectedIndexChanged;
                        editorElement.Filter = FilterWrapperDiscipline;
                        editorElement.ListElement.SelectedIndexChanged += CoteDGVDropdownEditor_SelectedIndexChanged;
                        break;

              }

    }

    When I choose in the first ComboBoxColumn, I want to intialize my second ComboBoxColumn, so I handle the "SelectedIndexChanged" event for each column.

    However I have a problem with this event. If I click on the New Row to start a new row, my first column is initialized, if I select an item in the first ComboBoxColumn, the "SelectedIndexChanged" event is fired, perfect. Next I click on the second ComboBoxColumn to enter in edition. The "OnMouseDown" event fires "SelectedIndexChanged" event several times for the first column with the selected value, next null value, next the selected value ...

    I try to replace the "SelectedIndexChanged" event by 'SelectedValueChanged" or "SelectedItemsChanged" bu I have the same problem. So I do not know how to distinguish when the "SelectedIndexChanged" event is invoked with the null value when it is the user who selected the empty item  or if it is the "OnMouseDown".

     

    Thank you

  8. Dimitar
    Admin
    Dimitar avatar
    2818 posts

    Posted 28 Jun Link to this post

    Hi Fabrizio,

    The editor is reused and you are still subscribed to the event while the cell is changed. This is why the event is fired many times. You can use the CellEndEdit event to unsubscribe from the event handler:
    private void RadGridView1_CellEndEdit(object sender, GridViewCellEventArgs e)
    {
        RadDropDownListEditor editor = e.ActiveEditor as RadDropDownListEditor;
        RadDropDownListEditorElement editorElement = editor?.EditorElement as RadDropDownListEditorElement;
        if (editorElement == null)
            return;
     
     
        editorElement.ListElement.SelectedIndexChanged -= CoteDGVDropdownEditor_SelectedIndexChanged;
     
     
    }

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

    Regards,
    Dimitar
    Progress Telerik
    Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
  9. Fabrizio
    Fabrizio avatar
    20 posts
    Member since:
    May 2019

    Posted 30 Jun in reply to Dimitar Link to this post

    Hello Dimitar

    Can you tell me if is it possible to re-evaluate a summary item of a gridview ?

    I have 3 bound gridviews. 

    When I insert a new row in the first gridview, when update is commited, I must update also the datasource of the two others gridview. The second and the thirth gridview are updated but summary rows are not re-evaluate.

    So can you tell me how I can re-evaluate them ?

    Thank you

    Best regards

  10. Dimitar
    Admin
    Dimitar avatar
    2818 posts

    Posted 01 Jul Link to this post

    Hello Fabrizio,

    You can use the following update method for this: 
    void searchButton_Click(object sender, EventArgs e)
    {
        this.radGridView1.TableElement.Update(GridUINotifyAction.DataChanged);
    }

    Please let me know if there is something else I can help you with. 

    Regards,
    Dimitar
    Progress Telerik
    Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
  11. Fabrizio
    Fabrizio avatar
    20 posts
    Member since:
    May 2019

    Posted 01 Jul in reply to Dimitar Link to this post

    Hello,

    It does not work.

    It's the datasource of a child view of my gridview that I want to update.

    Thank you

  12. Dimitar
    Admin
    Dimitar avatar
    2818 posts

    Posted 01 Jul Link to this post

    Hello Fabrizio,

    Another approach is to refresh the child template: 
    radGridView1.Templates[0].Refresh();

    Let me know how this works for you.

    Regards,
    Dimitar
    Progress Telerik
    Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
  13. Fabrizio
    Fabrizio avatar
    20 posts
    Member since:
    May 2019

    Posted 04 Jul in reply to Dimitar Link to this post

    Hi,

    In a bound RadGridView control, I enabled filtering.

    Can you tell me if is it possible to add a new item in the list of filter operators ?

    My goal is to have a new custom filter that allows to display rows by comparing the value of 2 columns 

    Thank you

  14. Dimitar
    Admin
    Dimitar avatar
    2818 posts

    Posted 04 Jul Link to this post

    Hello Fabrizio,

    The filter popup uses a context menu, and the ContextMenuOpening event will be fired in this case: Modifying the Default Context Menu | RadGridView | Telerik UI for WinForms

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

    Regards,
    Dimitar
    Progress Telerik
    Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
  15. Fabrizio
    Fabrizio avatar
    20 posts
    Member since:
    May 2019

    Posted 04 Jul in reply to Dimitar Link to this post

    Hello

    Thanks I saw this post and I implemented it. However, I didn't find how to do what I wanted ...

    I added item in the filter context menu but I would like to filter my gridview comparing value of 2 columns

     

    Thank you

  16. Dimitar
    Admin
    Dimitar avatar
    2818 posts

    Posted 08 Jul Link to this post

    Hello Fabrizio,

    The default filtering does not support this functionality. You will need to handle this by using the Custom Filtering. The custom filtering event gives you access to the row so you can compare both values. 

    I hope this helps. Should you have any other questions, do not hesitate to ask.

    Regards,
    Dimitar
    Progress Telerik
    Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Back to Top