Filter functionality true db grid in Visual basic

Question : Filter functionality true db grid in Visual basic
I am using truedbgrid 8.0 with VB 6.0 to bound data. I want to filter data displayed on grid using filter bar.  I used following code to try filtering.

TDBGrid1.DataSource = Adodc1
TDBGrid1.Columns(0).Width = 950
TDBGrid1.Columns(1).Width = 5650
TDBGrid1.FilterBar = True
TDBGrid1.FilterActive = True

but filter not working. what can be the problem? please help.


Solution: Filter functionality true db grid in Visual basic

Take a look at this:
Dim col As TrueOleDBGrid80.Column

Dim cols As TrueOleDBGrid80.Columns

Private Sub cmdClearFilter_Click()

‘ Clears filter from grid.

For Each col In TDBGrid1.Columns

col.FilterText = “”

Next col

Adodc1.Recordset.Filter = adFilterNone

End Sub

Private Sub TDBGrid1_FilterChange()

‘ Gets called when an action is performed on the filter bar.

On Error GoTo errHandler

Set cols = TDBGrid1.Columns

Dim c As Integer

c = TDBGrid1.col


Adodc1.Recordset.Filter = getFilter()

TDBGrid1.col = c

TDBGrid1.EditActive = True

Exit Sub


MsgBox Err.Source & “:” & vbCrLf & Err.Description

Call cmdClearFilter_Click

End Sub

Private Function getFilter() As String

‘ Creates the SQL statement in adodc1.recordset.filter and only filters

‘ text currently. It must be modified to filter other data types.

Dim tmp As String

Dim n As Integer

For Each col In cols

If Trim(col.FilterText) <> “” Then

n = n + 1

If n > 1 Then

tmp = tmp & ” AND ”

End If

tmp = tmp & col.DataField & ” LIKE ‘” & col.FilterText & “*'”

End If

Next col

getFilter = tmp

End Function