“Cannot find column” DataTable error while grouping or sorting Infragistics UltraWebGrid

If you’re binding an ADO.NET DataTable to Infragistics UltraWebGrid and then programmaticaly sort the grid (e.g. add a column to a band’s SortedColumns collection) you may get an error:

Cannot find column My Column Name.

with stack trace starting from grid databinding and finishing in datatable’s sorting:

at System.Data.DataTable.ParseSortString(String sortString)
at System.Data.DataView.CheckSort(String sort)
at System.Data.DataView.set_Sort(String value)
at Infragistics.WebUI.UltraWebGrid.DBBinding.ProcessDataViewForFillRows(DataView dataView, RowsCollection rows)
at Infragistics.WebUI.UltraWebGrid.DBBinding.FillRows(UltraWebGrid grid, RowsCollection rows, IEnumerable datasource)
at Infragistics.WebUI.UltraWebGrid.DBBinding.BindList(IEnumerable datasource)
at Infragistics.WebUI.UltraWebGrid.DBBinding.DataBind(Object dataSource, String dataMember)
at Infragistics.WebUI.UltraWebGrid.UltraWebGrid.DataBind()

If the grid binds OK without sorting and grouping, but fails with either – most likely the culprit is one of the columns in data table. Sort expression passed to a DataView is a comma separated list of column names to sort by. So, if your column name has a comma in it e.g. “My Column Name, For Real” – this presents a problem, since DataView will try to sort by 2 non-existing columns “My Column Name” (hence the error above) and “For Real”.

One way to deal with the problem is replace the comma with comma-like character “¸” called Cedilla (keystroke Alt+0184). So if after data retrieval you insert a loop like this:

'dtData is a data table already populated with data
For Each oCol As DataColumn In dtData.Columns
    oCol.ColumnName = oCol.ColumnName.Replace(",", "¸")
Next

then the sorting will perform correctly and without errors, and comma-like appearance will be preserved in column name.

Leave a Reply

Your email address will not be published. Required fields are marked *