Filter a Colom using filterbar

Posted by: Horst.Cesak on 14 November 2018, 6:15 pm EST

  • Posted 14 November 2018, 6:15 pm EST

    Hi,

    I have a database integer field.

    I use TrueDBGrid.

    The Colum is defined like this:

    col = new C1.Win.C1TrueDBGrid.C1DataColumn();

    col.Caption = “Device”;

    col.DataField = “DeviceType”;

    mGrid.Columns.Add(col);

    mGrid.Splits[0].DisplayColumns[col.Caption].Visible = true;

    mGrid.Splits[0].DisplayColumns[col.Caption].Locked = true;

    col.ValueItems.Translate = true;

    col.ValueItems.MaxComboItems = 2;

    col.ValueItems.CycleOnClick = true;

    col.ValueItems.Presentation = C1.Win.C1TrueDBGrid.PresentationEnum.ComboBox;

    col.ValueItems.Values.Add(new C1.Win.C1TrueDBGrid.ValueItem(“0”, “Device1”);

    col.ValueItems.Values.Add(new C1.Win.C1TrueDBGrid.ValueItem(“1”, “Device2”);

    Now I want for filter this column with the filterbar.

    It does nor ork.

    To you have an example, what I have do define for this colums.

    I also have a normal text column.

    for Example with the text “0001,0002,0003”

    I want filter this row if I enter 0002.

    How can I do this?

    Thanks Horst

  • Posted 15 November 2018, 9:02 pm EST

    Hi Horst!

    Please use the following propeties in your project, to enable filtering using FilterBar:

    mGrid.AllowFilter = true;
    mGrid.FilterBar = true;
    

    This should help you.

    Regards,

    Meenakshi

  • Posted 19 November 2018, 9:53 pm EST

    I know how to use filterbar normaly.

    With string colums type it works.

    My problem is that I do not know to handle the two case decribed in my mail above!

    Regards, Horst

  • Posted 20 November 2018, 5:49 pm EST

    Hi Horst,

    I’m assuming that “0001,0002,0003” is present in a single cell, and you want to filter rows based on any of the comma-separated value.

    While it is not possible to filter by specific portions of a string, you can modify the RowFilter of DataView so that entering 0002 will filter all the rows that contain “0002” anywhere in them.

    To do this, you would need to set AllowFilter to false so that you can handle Filter event:

    private void C1TrueDBGrid1_Filter(object sender, C1.Win.C1TrueDBGrid.FilterEventArgs e)
           {
               DataView dataView = (c1TrueDBGrid1.DataSource as DataTable).DefaultView;
    
               if (dataView.RowFilter != e.Condition)
               {
                   string condition = e.Condition;
                   if (condition.Length != 0)
                   {
                       condition = e.Condition;
                       if (condition.Contains($"[{c1TrueDBGrid1.Columns[0].Caption}]"))
                       {
                           int paramIndex = condition.IndexOf('\'', condition.IndexOf($"[{c1TrueDBGrid1.Columns[0].Caption}]")) + 1;
                           condition = condition.Insert(paramIndex, "*");
                       }
                   }
                   dataView.RowFilter = condition;
               }
           }
    

    This code would insert a “*” to make the RowFilter condition “value” to make it work like Contains operation.

    Also, could you please mention how you want to filter the “Device” column? The code you posted earlier filters correctly when filtering by “Device1” as well as using “0” or “1”.

    Please also see the attached sample for your reference.

    Regards,

    Jitender

    FilterMappedValues.zip

Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels