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

GGC filterbar using textboxes

Hi
I use this code, posted in this forum.
My problem is that the gridGrouping Control does not refresh the displayed data when i delete the text from the textbox filter.
This happens only If the column contains empty cells. If all the cells of the column contain data, then everything is OK. Can anybody give me a tip on this?

Thanks!

Here is the code:


Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

AddHandler Me.GridGroupingControl1.TableControlCurrentCellChanged, AddressOf gridGroupingControl1_TableControlCurrentCellChanged
AddHandler Me.GridGroupingControl1.TableControlCurrentCellActivating, AddressOf gridGroupingControl1_TableControlCurrentCellActivating
AddHandler Me.GridGroupingControl1.QueryCellStyleInfo, AddressOf gridGroupingControl1_QueryCellStyleInfo
Me.GridGroupingControl1.TableDescriptor.Columns("columnXXX").AllowFilter = True
Me.GridGroupingControl1.TableDescriptor.Columns("columnXXX").Appearance.FilterBarCell.CellType = "TextBox"

End Sub

#Region "Grid Grouping Control TEXTBOX FilterBar code"

Sub gridGroupingControl1_TableControlCurrentCellActivating(ByVal sender As Object, ByVal e As GridTableControlCurrentCellActivatingEventArgs)
Dim style As GridTableCellStyleInfo = e.TableControl.GetTableViewStyleInfo(e.Inner.RowIndex, e.Inner.ColIndex)
If TypeOf style.TableCellIdentity.DisplayElement Is GridFilterBarRow Then
e.TableControl.Table.CurrentRecordManager.LeaveRecord(False)
e.Inner.Cancel = Not (e.TableControl.Table.CurrentRecordManager.CurrentElement Is Nothing)
End If
End Sub

Private filterValues As Hashtable = New Hashtable



Private Sub gridGroupingControl1_TableControlCurrentCellChanged(ByVal sender As Object, ByVal e As GridTableControlEventArgs)
Dim cc As GridCurrentCell = e.TableControl.CurrentCell
Dim style As GridTableCellStyleInfo = e.TableControl.GetTableViewStyleInfo(cc.RowIndex, cc.ColIndex)
If TypeOf style.TableCellIdentity.DisplayElement Is GridFilterBarRow Then
cc.Lock()
Dim rowIndex As Integer = Me.GridGroupingControl1.Table.DisplayElements.IndexOf(style.TableCellIdentity.DisplayElement)
Dim colIndex As Integer = cc.ColIndex
Dim colName As String = style.TableCellIdentity.Column.Name
Dim expression As String = String.Format("[{0}] LIKE ''{1}*''", colName, cc.Renderer.ControlText)

If style.TableCellIdentity.Table.TableDescriptor.RecordFilters(colName) Is Nothing Then
style.TableCellIdentity.Table.TableDescriptor.RecordFilters.Add(New RecordFilterDescriptor(colName, expression))
filterValues.Add(colName, cc.Renderer.ControlText)
Else
style.TableCellIdentity.Table.TableDescriptor.RecordFilters(colName).Expression = expression
filterValues(colName) = cc.Renderer.ControlText
If cc.Renderer.ControlText = Nothing Then
filterValues.Remove(colName)
GridGroupingControl1.Refresh()
End If
End If
CType(sender, GridGroupingControl).Update()
cc.Unlock()
End If
End Sub



Private Sub gridGroupingControl1_QueryCellStyleInfo(ByVal sender As Object, ByVal e As GridTableCellStyleInfoEventArgs)
If e.TableCellIdentity.TableCellType = GridTableCellType.FilterBarCell AndAlso Not (e.TableCellIdentity.Column Is Nothing) Then
Dim name As String = e.TableCellIdentity.Column.Name
If Me.filterValues.ContainsKey(name) Then
e.Style.Text = Me.filterValues(name).ToString
End If
End If

End Sub

#End Region

2 Replies

AD Administrator Syncfusion Team September 8, 2006 11:32 AM UTC

Hi,

You can remove the RecordFilters in GridTableDescriptor, when you delete all the text from the cell. Here is a code snippet.

''Please change TableControlCurrentCellChanged event Else Part-> If ......
If cc.Renderer.ControlText = Nothing Or cc.Renderer.ControlText = String.Empty Then
style.TableCellIdentity.Table.TableDescriptor.RecordFilters.Remove(colName)
filterValues.Remove(colName)
End If

Let me know if this helps,

Best Regards,
Haneef


AD Administrator Syncfusion Team September 9, 2006 09:24 AM UTC

Thanks!
It is OK.
Best Regards

Loader.
Live Chat Icon For mobile
Up arrow icon