RC Search Highlight Demo w/ Metrics.Text
Printed From: Codejock Forums
Category: Codejock Products
Forum Name: Report Control
Forum Description: Topics Related to Codejock Report Control
URL: http://forum.codejock.com/forum_posts.asp?TID=17718
Printed Date: 27 November 2024 at 12:53pm Software Version: Web Wiz Forums 12.04 - http://www.webwizforums.com
Topic: RC Search Highlight Demo w/ Metrics.Text
Posted By: jpbro
Subject: RC Search Highlight Demo w/ Metrics.Text
Date Posted: 22 December 2010 at 9:25pm
I'm publishing this demo because I think it could be useful for others, however there are some apparent bugs in the RC that are preventing it from being perfectly useful at this point.
My hope is that the bugs will get fixed, and I can drop the [BUG] tag and replace it with [DEMO].
DEMO PURPOSE: To show the benefits of using ReportRecordItem.Value, ReportRecordItem.Caption and Metrics.Text in the BeforeDrawRow event of the ReportControl.
The techniques used here will allow us to have a "smart" sort for columns, editable plain text, and fancy markup for dynamic display purposes.
CURRENT PROBLEMS: 1) Metrics.Text values are interfering with Tooltips (Oleg has said this should be fixed for V15) 2) Metrics.Text values are interfering with inplace edit window text.
SCREENSHOT:
DOWNLOAD: uploads/2676/RcMetricsBugs.zip - uploads/2676/RcMetricsBugs.zip
------------- Product: Xtreme SuitePro (ActiveX) version 16.2.6 Platform: Windows XP - SP3
Language: Visual Basic 6.0 SP6
|
Replies:
Posted By: Xander75
Date Posted: 28 July 2011 at 7:31am
Just found this today as I was looking for a method to filter/search rows within a ReportControl with a TreeColumn.
The way in which I am using it is to display data only! So there's no editing involved within the grid, however I can confirm that this seems to work ok in v15.1.1 when in edit mode.
However if there is text in a column that is wider, normally an ellipsis appears and a tooltip is available, that disappears.
But despite this I have found this to be a useful addition to the ReportControl, with a little tweak to display numeric values as right aligned.
------------- Product: Xtreme SuitePro (ActiveX) v15.3.1 Platform: Windows 7 64-bit (SP1) Professional Edition Languages: C#.Net using Visual Studio 2012 & Visual Basic 6.0 (SP6)
|
Posted By: Willowmaster
Date Posted: 28 July 2011 at 7:41am
That looks really neat! We have a search in searchresults field. This would be a nice way the highlight te keyword.
------------- Product: Xtreme SuitePro (ActiveX) version 15.3.1
Platform: Windows XP (32bit) - SP 3 (on VMWare)
Language: Visual Basic 6.0
|
Posted By: Xander75
Date Posted: 28 July 2011 at 7:56am
Yeah that's what I thought when I found this, so I added the Highlight as an option (defaulted of course).
------------- Product: Xtreme SuitePro (ActiveX) v15.3.1 Platform: Windows 7 64-bit (SP1) Professional Edition Languages: C#.Net using Visual Studio 2012 & Visual Basic 6.0 (SP6)
|
Posted By: jpbro
Date Posted: 28 July 2011 at 9:33am
You can get the ellipsis by changing the Metrics.Text line in the BeforeDrawRow event to:
Metrics.Text = "<TextBlock TextTrimming='WordEllipsis'>" & l_MarkupText & "</TextBlock>"
|
or
Metrics.Text = "<TextBlock TextTrimming='CharacterEllipsis'>" & l_MarkupText & "</TextBlock>"
|
For some reason, I can't get the tooltips to show even if I set the Markup ToolTip attribute though :( Maybe a bug?
------------- Product: Xtreme SuitePro (ActiveX) version 16.2.6 Platform: Windows XP - SP3
Language: Visual Basic 6.0 SP6
|
Posted By: Xander75
Date Posted: 28 July 2011 at 9:49am
Hi jpbro,
Thanks for the code sample on how to resolve the ellipsis issue I was having. I went for the CharacterEllipsis method as it keeps it inline with the way the ReportControl works.
Yeah I tried the Markup ToolTip also but couldn't get anything to show either. Possibly a bug, or just not supported by CJ it's anyones guess!
------------- Product: Xtreme SuitePro (ActiveX) v15.3.1 Platform: Windows 7 64-bit (SP1) Professional Edition Languages: C#.Net using Visual Studio 2012 & Visual Basic 6.0 (SP6)
|
Posted By: jpbro
Date Posted: 28 July 2011 at 10:01am
Glad to help - sorry my post got a little mangled (fixed).
------------- Product: Xtreme SuitePro (ActiveX) version 16.2.6 Platform: Windows XP - SP3
Language: Visual Basic 6.0 SP6
|
Posted By: Aaron
Date Posted: 28 July 2011 at 11:32am
Xander75 wrote:
Hi jpbro,
Thanks for the code sample on how to resolve the ellipsis issue I was having. I went for the CharacterEllipsis method as it keeps it inline with the way the ReportControl works.
Yeah I tried the Markup ToolTip also but couldn't get anything to show either. Possibly a bug, or just not supported by CJ it's anyones guess!
|
Hi,
I have Tooltips in ReportControl with MarkUp... Or is it with new version?
------------- Product: Xtreme SuitePro (ActiveX) version 15.0.2
Platform: Windows XP (32bit) - SP 2
Language: Visual Basic 6.0
Zero replies is not an option....
|
Posted By: Xander75
Date Posted: 28 July 2011 at 11:38am
Hi Aaron,
Yeah I am using v15.1.1 and the ToolTip does not appear to display for either the Span or TextBlock within the ReportControl.
Can you post a sample of how you done this so I can at least clarify if this is another bug with v15.1.1?
------------- Product: Xtreme SuitePro (ActiveX) v15.3.1 Platform: Windows 7 64-bit (SP1) Professional Edition Languages: C#.Net using Visual Studio 2012 & Visual Basic 6.0 (SP6)
|
Posted By: Aaron
Date Posted: 28 July 2011 at 12:54pm
Hi,
With RC .EnableMarkup = True With .Records.Add With .AddItem("1") .Caption = "<TextBlock ToolTip='abcd'>abc</TextBlock>" End With
Produces this:
------------- Product: Xtreme SuitePro (ActiveX) version 15.0.2
Platform: Windows XP (32bit) - SP 2
Language: Visual Basic 6.0
Zero replies is not an option....
|
Posted By: Xander75
Date Posted: 29 July 2011 at 3:55am
Thanks Aaron,
From your snippet of code I successfully managed to tweak the code to get the ToolTip property working with jpbro's Highlight code.
I updated the code in the BeforeDrawRow event:
Private Sub ReportControl1_BeforeDrawRow(ByVal Row As XtremeReportControl.IReportRow, ByVal Item As XtremeReportControl.IReportRecordItem, ByVal Metrics As XtremeReportControl.IReportRecordItemMetrics) Dim l_Text As String Dim l_MarkupText As String Dim l_Search As String Dim l_MatchPos As Long Dim l_LastMatchPos As Long Dim l_EntitySpacedText As String Dim i As Long If Me.ReportControl1.InplaceEditHwnd <> 0 Then If Row Is Me.ReportControl1.FocusedRow Then If Item.Index = Me.ReportControl1.FocusedColumn.ItemIndex Then ' Added code to help avoid a nasty crash when in edit mode when using the Item.Value, using Item.Caption shows the Markup... l_Text = Item.Value SendMessage rpcGrid(Index).InplaceEditHwnd, WM_SETTEXT, 0, ByVal l_Text Exit Sub End If End If End If l_Text = EncodePlainTextForXaml(Item.Value) l_Search = EncodePlainTextForXaml(txtSearch.Text) If LenB(l_Search) <> 0 Then l_LastMatchPos = 1 l_MatchPos = 1 Do l_MatchPos = InStr(l_MatchPos, l_Text, l_Search, vbTextCompare) If l_MatchPos > 0 Then m_FoundMatch = True
l_EntitySpacedText = Mid$(l_Text, l_MatchPos, Len(l_Search)) l_EntitySpacedText = Replace$(l_EntitySpacedText, " ", " ") ' Make sure leading and trailing spaces get highlighted by using the space entity.
l_MarkupText = l_MarkupText & Mid$(l_Text, l_LastMatchPos, l_MatchPos - l_LastMatchPos) l_MarkupText = l_MarkupText & "<Span Background='#A0FFFF00' Foreground='Black'><Bold>" & l_EntitySpacedText & "</Bold></Span>"
l_LastMatchPos = l_MatchPos + Len(l_Search) l_MatchPos = l_MatchPos + 1 Else l_MarkupText = l_MarkupText & Mid$(l_Text, l_LastMatchPos) End If Loop While l_MatchPos > 0
' Right Align Numeric Values If IsNumeric(l_Text) Then Row.Record.Item(Item.Index).Caption = "<TextBlock TextAlignment='Right' TextTrimming='CharacterEllipsis' ToolTip='" & l_Text & "'>" & l_MarkupText & "</TextBlock>" Else Row.Record.Item(Item.Index).Caption = "<TextBlock TextTrimming='CharacterEllipsis' ToolTip='" & l_Text & "'>" & l_MarkupText & "</TextBlock>" End If Else Row.Record.Item(Item.Index).Caption = l_Text End If End Sub
|
This works fine for my needs, however when I tested this in jpbro's original demo I get the code to crash when in edit mode. But as I am not using the ReportControl in edit mode that's ok by me
------------- Product: Xtreme SuitePro (ActiveX) v15.3.1 Platform: Windows 7 64-bit (SP1) Professional Edition Languages: C#.Net using Visual Studio 2012 & Visual Basic 6.0 (SP6)
|
Posted By: Aaron
Date Posted: 29 July 2011 at 5:37am
Hi Alexander,
I tried your code with V15.0.2 and it works OK, at least no crash.
------------- Product: Xtreme SuitePro (ActiveX) version 15.0.2
Platform: Windows XP (32bit) - SP 2
Language: Visual Basic 6.0
Zero replies is not an option....
|
Posted By: Xander75
Date Posted: 29 July 2011 at 5:51am
Hi Aaron,
The crash only happened as I had changed the line:
SendMessage rpcGrid(Index).InplaceEditHwnd, WM_SETTEXT, 0, ByVal Item.Caption
| to
SendMessage rpcGrid(Index).InplaceEditHwnd, WM_SETTEXT, 0, ByVal Item.Value
| However by updating the code to:
l_Text = Item.Value SendMessage rpcGrid(Index).InplaceEditHwnd, WM_SETTEXT, 0, ByVal l_Text
| Helps fix the crashing issue and displays the text in edit mode correctly, although there is a slight flicker of Markup.
I have updated my previous post above with this fix.
------------- Product: Xtreme SuitePro (ActiveX) v15.3.1 Platform: Windows 7 64-bit (SP1) Professional Edition Languages: C#.Net using Visual Studio 2012 & Visual Basic 6.0 (SP6)
|
Posted By: JamGodz
Date Posted: 19 November 2011 at 6:26am
Hi Sir Xander! Good Day!
Just want to know of how you do it, the filter function... can you teach/post some sample code? i saw your screenshot and that's all i need especially those above the reportcontrol... please...
Thank you.
|
Posted By: Xander75
Date Posted: 06 December 2011 at 5:13am
Hi JamGodz,
Well as for the code you can get this from jpbro's first post and change the code accordinly as per my fifth post.
As for the filter, well it's nothing more than a FlatEdit & PushButton control. I changed the way in which the filter worked by disabling and enabling a timer each time the filter was changed so as that it meant it would only filter after a few seconds of inactivity.
Private Sub tmrFilter_Timer() tmrFilter.Enabled = False Dim i As Long m_FoundMatch = False For i = 0 To 3 With rpcGrid(i) .FilterText = Trim$(txtFilter.Text) .Navigator.MoveFirstVisibleRow .Populate .Redraw End With Next If LenB(txtFilter.Text) > 0 Then If m_FoundMatch Then For i = 0 To 3 rpcGrid(i).ExpandAll True Next txtFilter.BackColor = vbWindowBackground Else txtFilter.BackColor = &H8282FF End If Else For i = 0 To 3 rpcGrid(i).CollapseAll Next txtFilter.BackColor = vbWindowBackground End If For i = 0 To 3 With rpcGrid(i) .Navigator.MoveFirstVisibleRow End With Next End Sub
Private Sub txtFilter_Change() tmrFilter.Enabled = False tmrFilter.Enabled = True If Trim$(txtFilter.Text) = vbNullString Then Call tmrFilter_Timer End Sub
|
As for the checkbox "Highlight Filtered Text", I added this later on and this can be added in the BeforeDrawRow event, simlpy replace the block of code in post five:
' Right Align Numeric Values If IsNumeric(l_Text) Then Row.Record.Item(Item.Index).Caption = "<TextBlock TextAlignment='Right' TextTrimming='CharacterEllipsis' ToolTip='" & l_Text & "'>" & l_MarkupText & "</TextBlock>" Else Row.Record.Item(Item.Index).Caption = "<TextBlock TextTrimming='CharacterEllipsis' ToolTip='" & l_Text & "'>" & l_MarkupText & "</TextBlock>" End If
|
with the following code:
If CommandBars.FindControl(, ID_TOOLBAR_FILTER_HIGHLIGHT).Checked Then ' Right Align Numeric Values If IsNumeric(l_Text) Then Row.Record.Item(Item.Index).Caption = "<TextBlock TextAlignment='Right' TextTrimming='CharacterEllipsis' ToolTip='" & l_Text & "'>" & l_MarkupText & "</TextBlock>" Else Row.Record.Item(Item.Index).Caption = "<TextBlock TextTrimming='CharacterEllipsis' ToolTip='" & l_Text & "'>" & l_MarkupText & "</TextBlock>" End If Else Row.Record.Item(Item.Index).Caption = l_Text End If
|
------------- Product: Xtreme SuitePro (ActiveX) v15.3.1 Platform: Windows 7 64-bit (SP1) Professional Edition Languages: C#.Net using Visual Studio 2012 & Visual Basic 6.0 (SP6)
|
Posted By: JamGodz
Date Posted: 08 December 2011 at 3:26am
Hi Xander! thank you for the reply and specially the code.. but i have found an error in
l_Text = EncodePlainTextForXaml(Item.Value)
its says "Object Variable or With block variable not set"
i have a 2 grouprow in my RC. how can avoid this error?
and it doesnt hightlight the grouprow.
thanks?
|
Posted By: Xander75
Date Posted: 09 December 2011 at 3:31am
Hi JamGodz,
I guess this issue is occuring due to the use of the GroupRow. I didn't test for that as I wasn't using it in my project, but I guess you'll need to add some code for Row.GroupRow.
If you can upload a sample I will try and help you out, although now that this forum takes a while for posts to display I can't imagine I can help before the weekend plus I am out of the office on Monday & Tuesday!
------------- Product: Xtreme SuitePro (ActiveX) v15.3.1 Platform: Windows 7 64-bit (SP1) Professional Edition Languages: C#.Net using Visual Studio 2012 & Visual Basic 6.0 (SP6)
|
Posted By: jpbro
Date Posted: 09 December 2011 at 1:58pm
At the top of the BeforeDrawRow event, you could test like this:
If Row Is Nothing Then Exit Sub If Row.GroupRow Then Exit Sub If Item Is Nothing Then Exit Sub
|
This should prevent any errors (aircode, so hopefully I haven't made a mistake).
------------- Product: Xtreme SuitePro (ActiveX) version 16.2.6 Platform: Windows XP - SP3
Language: Visual Basic 6.0 SP6
|
Posted By: JamGodz
Date Posted: 10 December 2011 at 7:41am
Hi jpbro and Xander, below is my modification to cater the grouprow highlight. but it only apply to grouprow coz i only trap to row.grouprow, i need also to filter/highlight the item not only the grouprow.
Pls any suggestion would be greatly appreciated.
Thanks.
Private Sub wndList_BeforeDrawRow(ByVal Row As XtremeReportControl.IReportRow, ByVal Item As XtremeReportControl.IReportRecordItem, ByVal Metrics As XtremeReportControl.IReportRecordItemMetrics) If wndList.InplaceEditHwnd <> 0 Then If Row Is wndList.FocusedRow Then If Item.index = wndList.FocusedColumn.ItemIndex Then ' Added code to help avoid a nasty crash when in edit mode when using the Item.Value, using Item.Caption shows the Markup... l_Text = Item.Value SendMessage wndList(Item.index).InplaceEditHwnd, WM_SETTEXT, 0, ByVal l_Text Exit Sub End If End If End If If Row.GroupRow Then Dim GroupRow As ReportGroupRow Set GroupRow = Row 'l_Text = EncodePlainTextForXaml(Item.Value) l_Text = EncodePlainTextForXaml(HTMLClean(GroupRow.GroupCaption)) l_Search = EncodePlainTextForXaml(txtFilter.Text) If LenB(l_Search) <> 0 Then l_LastMatchPos = 1 l_MatchPos = 1 Do l_MatchPos = InStr(l_MatchPos, l_Text, l_Search, vbTextCompare) If l_MatchPos > 0 Then m_FoundMatch = True l_EntitySpacedText = Mid$(l_Text, l_MatchPos, Len(l_Search)) l_EntitySpacedText = Replace$(l_EntitySpacedText, " ", " ") ' Make sure leading and trailing spaces get highlighted by using the space entity. l_MarkupText = l_MarkupText & Mid$(l_Text, l_LastMatchPos, l_MatchPos - IIf(l_LastMatchPos > l_MatchPos, l_LastMatchPos = l_MatchPos, l_LastMatchPos)) l_MarkupText = l_MarkupText & "<Span Background='#A0FFFF00' Foreground='Black'><Bold>" & l_EntitySpacedText & "</Bold></Span>" l_LastMatchPos = l_MatchPos + Len(l_Search) l_MatchPos = l_MatchPos + 1 Else l_MarkupText = l_MarkupText & Mid$(l_Text, l_LastMatchPos) End If Loop While l_MatchPos > 0 GroupRow.GroupCaption = "<TextBlock TextTrimming='CharacterEllipsis' ToolTip='" & l_Text & "'>" & l_MarkupText & "</TextBlock>" Else GroupRow.GroupCaption = HTMLClean(l_Text) End If End If End Sub
|
below are my function to strip HTML tags.
Public Function HTMLClean(ByVal strText As String) As String Dim objRegEx As VBScript_RegExp_55.RegExp ' replace <br>'s for a newline strText = Replace$(strText, "<br>", Chr$(10), 1, -1, vbTextCompare) ' replace non-breaking spaces for a space strText = Replace$(strText, " ", Chr$(32), 1, -1, vbTextCompare) ' create new regex object Set objRegEx = New VBScript_RegExp_55.RegExp objRegEx.Global = True ' don't just operate on first find. ' remove HTML tags objRegEx.Pattern = "<[^>]*>" strText = objRegEx.Replace(strText, "") ' ditch excessive white space objRegEx.Pattern = "\s+" strText = objRegEx.Replace(strText, " ")
Set objRegEx = Nothing
' named-entities strText = Replace$(strText, ">", ">", 1, -1, vbTextCompare) strText = Replace$(strText, "<", "<", 1, -1, vbTextCompare)
' insert your favourite named-entities here. strText = Replace$(strText, "&", "&", 1, -1, vbTextCompare) ' must do last ' return HTMLClean = strText End Function
|
[]
|
Posted By: jpbro
Date Posted: 12 December 2011 at 10:11am
I haven't tested this, but it might work (may need some modifications, but it should put you on the right track):
Private Sub wndList_BeforeDrawRow(ByVal Row As XtremeReportControl.IReportRow, ByVal Item As XtremeReportControl.IReportRecordItem, ByVal Metrics As XtremeReportControl.IReportRecordItemMetrics) If wndList.InplaceEditHwnd <> 0 Then If Row Is wndList.FocusedRow Then If Item.index = wndList.FocusedColumn.ItemIndex Then ' Added code to help avoid a nasty crash when in edit mode when using the Item.Value, using Item.Caption shows the Markup... l_Text = Item.Value SendMessage wndList(Item.index).InplaceEditHwnd, WM_SETTEXT, 0, ByVal l_Text Exit Sub End If End If End If
Dim GroupRow As ReportGroupRow
If Row.GroupRow Then Set GroupRow = Row l_Text = EncodePlainTextForXaml(HTMLClean(GroupRow.GroupCaption)) Else l_Text = EncodePlainTextForXaml(Item.Value) End If l_Search = EncodePlainTextForXaml(txtFilter.Text) If LenB(l_Search) <> 0 Then l_LastMatchPos = 1 l_MatchPos = 1
Do l_MatchPos = InStr(l_MatchPos, l_Text, l_Search, vbTextCompare) If l_MatchPos > 0 Then m_FoundMatch = True
l_EntitySpacedText = Mid$(l_Text, l_MatchPos, Len(l_Search)) l_EntitySpacedText = Replace$(l_EntitySpacedText, " ", " ") ' Make sure leading and trailing spaces get highlighted by using the space entity.
l_MarkupText = l_MarkupText & Mid$(l_Text, l_LastMatchPos, l_MatchPos - IIf(l_LastMatchPos > l_MatchPos, l_LastMatchPos = l_MatchPos, l_LastMatchPos)) l_MarkupText = l_MarkupText & "<Span Background='#A0FFFF00' Foreground='Black'><Bold>" & l_EntitySpacedText & "</Bold></Span>"
l_LastMatchPos = l_MatchPos + Len(l_Search) l_MatchPos = l_MatchPos + 1 Else l_MarkupText = l_MarkupText & Mid$(l_Text, l_LastMatchPos) End If Loop While l_MatchPos > 0
l_Text = "<TextBlock TextTrimming='CharacterEllipsis' ToolTip='" & l_Text & "'>" & l_MarkupText & "</TextBlock>" Else l_Text = HTMLClean(l_Text) End If
If GroupRow Is Nothing Then Item.Caption = l_Text Else GroupRow.GroupCaption = l_Text End If End Sub
|
------------- Product: Xtreme SuitePro (ActiveX) version 16.2.6 Platform: Windows XP - SP3
Language: Visual Basic 6.0 SP6
|
Posted By: JamGodz
Date Posted: 13 December 2011 at 11:42pm
Hi jpbro
Thank you so much.. it really work!
but how i implented the filter to display only the hilighted data in the reportcontrol? using the txtFilter_Change event. But also how you add the flatedit in the toolbar without any problem coz i have successfully attached the flatedit control but when im going to click the control will move to somewhere in the form or to its original position in design time, but when i used vb6 intrinsic control this will not happen..
pls help.
thanks..
|
|