Ticket Q354391
Visible to All Users

ASPxGridView - Change default value of Filter Row condition

created 13 years ago

I have used this solution from http://www.devexpress.com/Support/Center/p/Q109328.aspx to preset all filter AutoFilterCondition to "Contains".
However, if you field is an integer, the "Contains" is not a valid filter option, and if the integer column is filtered upon, no results are returned.
How can I only apply "Contains" to the AutoFilterCondition for only the field types that have this option?
protected void Page_Load(object sender, EventArgs e) {
    if (!IsPostBack)
        foreach (GridViewColumn col in ASPxGridView1.Columns)
            if (col is GridViewDataColumn)
                ((GridViewDataColumn)col).Settings.AutoFilterCondition = AutoFilterCondition.Contains;
}

Comments (2)
DevExpress Support Team 13 years ago

    Hello Scott:
    The ASPxGridView control does not provide a property or method that allows checking which filter conditions are acceptable for this column. It depends on the column's data type.
    I assume that you can set the initial AutoFilterCondition to Equals for all columns in the grid, retrieve columns which have string data from the Columns collection by their FieldNames and set the AutoFilterCondition to Contains for these columns only.
    Thanks
    Kate.

      I agree Kate,
      Within the gridview column loop, how can I determine the column's data type? that is the syntax I am having problems with.

      Answers approved by DevExpress Support

      created 13 years ago (modified 12 years ago)

      Hello Scott,
      Thank you for your reply.
      Usually it is known what type column data items have. You can check the column's FieldName property and initialize the AutoFilterCondition setting only for necessary columns.
      If you need to check a data item's type at runtime, you need to use the ASPxClientGridView.GetRowValues method:

      C#
      protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) foreach (GridViewColumn col in grid.Columns) { GridViewDataColumn c = col as GridViewDataColumn; if ((c != null) && !(c.Grid.GetRowValues(0, c.FieldName) is int)) { c.Settings.AutoFilterCondition = AutoFilterCondition.Contains; } } }

      If you have any other questions, please contact us at any time.
      Updated, Owner's solution:
      Here is a VB version in case anyone needs.
      This sub is ran on initial Page_Load event.
      Public Sub SetGridViewFilterModeToContains(ByVal gv As ASPxGridView)
                  For Each col As GridViewColumn In gv.Columns
                      Dim c As GridViewDataColumn = TryCast(col, GridViewDataColumn)
                      If (c IsNot Nothing) AndAlso Not (TypeOf c.Grid.GetRowValues(0, c.FieldName) Is Integer) Then
                          c.Settings.AutoFilterCondition = AutoFilterCondition.Contains
                      End If
                  Next
      End Sub

        Comments (2)

          Your solution worked great. thanks!
          Here is a VB version in case anyone needs.
          This sub is ran on initial Page_Load event.
          Public Sub SetGridViewFilterModeToContains(ByVal gv As ASPxGridView)
                      For Each col As GridViewColumn In gv.Columns
                          Dim c As GridViewDataColumn = TryCast(col, GridViewDataColumn)
                          If (c IsNot Nothing) AndAlso Not (TypeOf c.Grid.GetRowValues(0, c.FieldName) Is Integer) Then
                              c.Settings.AutoFilterCondition = AutoFilterCondition.Contains
                          End If
                      Next
          End Sub

          DevExpress Support Team 13 years ago

            Hello Scott,
            I am glad to hear that our solution meets your requirement. I also appreciate your feedback that can be useful for other users.
            If you encounter any difficulty using our components, feel free to contact us at any time.
            Best regards,
            Vladimir

            Disclaimer: The information provided on DevExpress.com and affiliated web properties (including the DevExpress Support Center) is provided "as is" without warranty of any kind. Developer Express Inc disclaims all warranties, either express or implied, including the warranties of merchantability and fitness for a particular purpose. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.

            Confidential Information: Developer Express Inc does not wish to receive, will not act to procure, nor will it solicit, confidential or proprietary materials and information from you through the DevExpress Support Center or its web properties. Any and all materials or information divulged during chats, email communications, online discussions, Support Center tickets, or made available to Developer Express Inc in any manner will be deemed NOT to be confidential by Developer Express Inc. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.