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

Null values in autofilters

Sort Posts: Previous Next
  •  02-08-2010, 7:52 PM Post no. 25704

    Null values in autofilters

    Hi all.

    I have a datagrid showing data from an ODE DataTable, and I have autofiltering enabled. Very cool. But I would like the autofilter drop-down lists to include "null" as one of the distinct values available for filtering. How can I achieve this?

    Filed under:
  •  02-09-2010, 1:56 AM Post no. 25705 in reply to 25704

    Re: Null values in autofilters

    This may have changed since v3.2 but I add a handler to the DataGridItemProperty QueryDistinctValue and in there set an appropriate value to match the null elements.

    It is not ideal as I have ended up with a "dummy" value for each of the data types as otherwise I was getting an exception during the actual compare. 

    For example:

    DataGridItemProperty dgip = new DataGridItemProperty(dtColumn.ColumnName, dtColumn.DataType);

    if (dgcvDataContent.DistinctValuesConstraint == DistinctValuesConstraint.Filtered)

    {

    dgip.QueryDistinctValue += new EventHandler<QueryDistinctValueEventArgs>(dgip_QueryDistinctValue);

    }

     

    protected void dgip_QueryDistinctValue(object sender, QueryDistinctValueEventArgs e)

    {

    if (e.DataSourceValue == null || e.DataSourceValue == DBNull.Value)

    {

    DataGridItemProperty dgip = sender as DataGridItemProperty;

    string sFullName = dgip.DataType.FullName;

    if (sFullName.Contains("String"))

    {

    e.DistinctValue = "";

    }

    else if (sFullName.Contains("DateTime"))

    {

    e.DistinctValue = DateTime.MinValue;

    }

    else if (sFullName.Contains("Double"))

    {

    e.DistinctValue = 0.0;

    }

    else

    {

    e.DistinctValue = 0;

    }

    }

    else

    {

    e.DistinctValue = e.DataSourceValue;

    }

    }

     

  •  02-09-2010, 5:30 PM Post no. 25719 in reply to 25705

    Re: Null values in autofilters

    Hi Tony,

    This other forum thread might also be of help:
    http://xceed.com/CS/forums/thread/22975.aspx

     


    ** Quick Tip: Clients with an active support subscription should be sending their questions by email if they wish to benefit from the faster response time. Thanks!


    Diane Lafontaine
    Technical Support
    Xceed Software Inc.
  •  02-10-2010, 2:41 AM Post no. 25726 in reply to 25719

    Re: Null values in autofilters

    I had tried that but got exceptions when using the filter on columns with:

     System.InvalidOperationException: Failed to compare two elements in the array, --> System.ArgumentException: Object must be of type DateTime.

    (or other data type depending on the data type). Hence the more complex solution.

     

     

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