We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

FilterBar + DataBoundGrid

It seems, when setting the databound grid property to a dataview the filterbar is lost. For example.... DataView dv = new DataView(ds.Tables["AppointmentByStatusAndGeoID"]); dv.RowFilter = "AppointmentDate > #" + System.DateTime.Today.Date + "# AND " + "AppointmentDate < #" + System.DateTime.Today.Date.AddDays(1) + "#"; this.grdAppointments2.DataSource = dv; //create the filter bar and display it GridFilterBar theFilterBar = new GridFilterBar(); //catch the creating column header event so we can turn off unwanted filter headers //needs to be hooked before WireGrid call to catch things... theFilterBar.CreatingColumnHeader += new GridFilterBarCreatingColumnHeaderEventHandler(GridFilterBarCreatingColumnHeader); //create a style for the filter cells that uses TextBox GridStyleInfo style = new GridStyleInfo(); style.ModifyStyle(this.grdAppointments2.BaseStylesMap["Header"].StyleInfo, StyleModifyType.Copy); style.CellType = "ComboBox"; style.ExclusiveChoiceList = true; style.BaseStyle = "Standard"; style.Font.Bold = false; style.BackColor = this.grdAppointments2.TableStyle.BackColor; style.Borders.Bottom = new GridBorder(GridBorderStyle.Dashed); style.DropDownStyle = GridDropDownStyle.AutoComplete; theFilterBar.WireGrid(this.grdAppointments2, style); The filter bar is not there. If I set the datasource to a datatable then the filterbar shows up. Cheers, JF

3 Replies

AD Administrator Syncfusion Team November 15, 2003 07:42 PM UTC

This is a known limitation. Currently, you can only use either a dataset/datatable or a datatable by itself as the grid's datasource/datamember if you want to use filterbars. You can derive the GridFilterBar class to extend it to support using a DataView as the datasource for the grid. We will add support for using a DataView as the datasource in a future release. Here is some code:
    Public Class SyncGridFilterBar
        Inherits GridFilterBar
        Private _grid As GridDataBoundGrid
        Protected Overrides Function GetDataTable() As DataTable
            If _grid.DataSource Is Nothing Then
                Return Nothing
            End If
            If _grid.DataSource.GetType Is GetType(DataTable) Then
                Return CType(_grid.DataSource, DataTable)
            ElseIf _grid.DataSource.GetType Is GetType(DataView) Then
                Return CType(_grid.DataSource, DataView).Table
            End If
        End Function

        Public Overloads Overrides Sub WireGrid(ByVal grid As GridDataBoundGrid, ByVal style As GridStyleInfo)
            _grid = grid
            MyBase.WireGrid(grid, style)
        End Sub
    End Class


RD Revathi Dhamotharan January 22, 2020 02:37 AM UTC

Hi,

Is it possible to add a filter bar for a griddataboundgrid if the datasource is set to a dataview and datamember is a datarelation. When i try to wire up the filter bar, it gives me an error saying, it cannot find a column but it is there. The exception is thrown at parsesortstring in wiregrid method. Can you please tell me if this ispossible or is there a workaround?

Thank you,
Revathi


AR Arulpriya Ramalingam Syncfusion Team January 22, 2020 06:25 PM UTC

 
Greetings from Syncfusion support. 
 
We have validated the reported use case at our end and as per our DataBondGrid current behavior, it does not have support to add relational dataview as DataSource whereas, it have support to add RelatedDataTable (UI will update with the main table only). So, we would suggest you to use the DataTable as binding source for the grid. If you are trying to add nested tables in the Grid UI(Parent and child table hierarchy), we would recommend you to use the SfDataGrid which has advanced features like Filtering, Sorting, Exporting and etc. please make use of below UG to know more about the SfDataGrid. 
 
 
Regards, 
Arulpriya 


Loader.
Live Chat Icon For mobile
Up arrow icon