• Home
  • About
  • Resume

Solution for Infragistics WebDataGrid filtering error “Length cannot be less than zero”

By , 02/01/2013 11:49 AM

Infragistics WebDataGrid/WHDG controls for ASP.NET offer nice filtering features. Out of the box you just have to enable the behavior and badabingo:

WebDataGrid filtering

There is one glitch though in the way text filtering is implemented: If you enter an empty string as a filter value – an error is thrown:

Async refresh failed. Length cannot be less than zero

Apparently internal grid code cannot handle empty strings (as of version 12.2) so we have to take matter in our own hands.

Add following code to your grid’s DataFiltering event handler:

Protected Sub xMyGrid_DataFiltering(sender As Object, e As GridControls.FilteringEventArgs) Handles xMyGrid.DataFiltering

    For I As Integer = e.ColumnFilters.Count - 1 To 0 Step -1
        If e.ColumnFilters(I).ColumnType = "string" Then
            If DirectCast(e.ColumnFilters(I).Condition, GridControls.RuleTextNode).Value = "" Then
                e.ColumnFilters.RemoveAt(I)
            End If
        End If
    Next

    'rebind the grid to datasource as needed
End Sub

Essentially what is happening here – we loop thru all column filters, check if it’s a text column and if it is – check its filter ‘s value. If it’s an empty string – we simple removing the filter from the collection. Error is gone, filter is performed as expected.

One Response to “Solution for Infragistics WebDataGrid filtering error “Length cannot be less than zero””

  1. Alan Halama says:

    This issue is resolved in the latest service release so an alternative to your workaround would be to download the latest service release from the My Keys and Downloads page:
    https://www.infragistics.com/my-account/keys-and-downloads/

    Note that to download the service release you must have your NetAdvantage key registered to your profile. You could also install the service release using the platform installer when installing NetAdvantage for ASP.NET.

Leave a Reply

Panorama Theme by Themocracy