Welcome to the Xceed Community | Help
Community Search  
More Search Options

How to filter a multi-valued column?

Sort Posts: Previous Next
  •  03-08-2012, 5:45 AM Post no. 31816

    How to filter a multi-valued column?

    Hi. Is there an example available that shows how to implement filtering on a column that allows multiple values (is bound to a Collection)?

    Say I have a grid that shows events, where each event can have multiple speakers. A column titled "Speaker" would be rendered as a ListBox, per each row.

    I would like to get the filter row to work with the multi-valued speaker column, so a user can enter "Scott" and see only the rows where Scott is a speaker. And/or get the Excel-like filtering to work with the column as well (the drop-down filtering option).

    All the examples I have found so far have been with single-valued columns. 

  •  03-08-2012, 10:22 PM Post no. 31820 in reply to 31816

    Re: How to filter a multi-valued column?

    Hi thomas, 

     Can you provide us with a self contained sample application that demonstrates how your grid is set up? 

    You can send it to support@xceed.com.

    Please include a reference to this email thread in your email.  


    Best Regards,

    Michel Dahdah
    Technical Support
    Xceed Software inc.
  •  03-19-2012, 12:23 PM Post no. 31860 in reply to 31820

    Re: How to filter a multi-valued column?

    OK, I've sent in an example solution just now.

    (I shall post back here with the solution to my question, if/when I find one - in case you have a similar question).

  •  04-04-2012, 6:52 AM Post no. 31942 in reply to 31860

    Re: How to filter a multi-valued column?

    Response from Marc [XCeed tech support] below. I have implemented the solution accordingly, and, yes - it works ;-)

    1) I would like be able to filter the second column (Speakers) just like the first row (Event name). Right now, the Excel-like filtering (drop down on the column header) displays a list of distinct values, but when I click one of these, no filter is applied.

    > This will require you to redo the AutoFilterControl style and handle the filtering. Here is the default template of the AutoFilterControl in one of the blogs that Michel posted:

    http://xceed.com/CS/blogs/techside/archive/2011/11/08/adding-a-select-all-button-the-autofiltercontrol.aspx

    This should help you when handling the filtering.


    2) I would also like the filter row to work for the second column. Ie. if the user enters "Alf", all items with Alfred as the speaker are shown. "ny" will show all with Benny as speaker, given the current data set.

    > In order to achieve this, you will need to supply your own FilterCell editor and handle the TextChanged event on the TextBox. Then you must do a refresh so that the Filter event can get triggered. In the Filter event, you can check if the value of your object contains the string in the TextBox.

    XAML

    -----------

    <DataTemplate>

          <xcdg:FilterRow Background="LightYellow" >

                <xcdg:FilterCell FieldName="Speakers">

                     <xcdg:FilterCell.FilterEditorTemplate>

                             <DataTemplate>

                                  <TextBox Background="Yellow" BorderThickness="0" TextChanged="TextBox_TextChanged"/>

                             </DataTemplate>

                     </xcdg:FilterCell.FilterEditorTemplate>

                </xcdg:FilterCell>

          </xcdg:FilterRow>

    </DataTemplate>

    -----------

    C#

    -----------

    string lastText = "";

    private void TextBox_TextChanged(object sender, TextChangedEventArgs e) {

        lastText = (sender as TextBox).Text;

        (dataGridControl1.ItemsSource as DataGridCollectionView).Refresh();

    }

     

    private void DataGridCollectionViewSource_Filter(object sender, FilterEventArgs e) {

        foreach (var speaker in (e.Item as Event).Speakers)

        {

            if (speaker.Name.Contains(lastText))

            {

                e.Accepted = true;

                return;

            }

        }

        e.Accepted = false;

    }

    ----------- 

    Filed under:
View as RSS news feed in XML
Contact | Site Map | Reviews | Legal Terms of Use | Trademarks | Privacy Statement Copyright 2011 Xceed Software Inc.