For a Windows Forms app I'm creating a "Google Suggest" type feature with a textbox and an UltraWinGrid. It's working pretty well, but I can't figure out one thing.If "mac" is typed in the textbox, the grid displays:Mac AttackBig MacLittle MacBurger Machine
I'd like to format the text in each cell like so:Mac Attack Big Mac Little Mac Burger Machine
Possible? Thanks.-Jeremy
Thanks Mike. There must be perfomance improvement opportunities in the Ultragrid source code for FormattedText rendering, but I was able to take a slightly different route to make it usable for my purposes.
Instead of filtering the list in place I'm now building a seperate list of only matches and using it as the grid's data source. This way there are fewer rows to render. Also, as a side benefit, when building the suggestion list I can use regex to wrap the typed in text with bold tags which display as bold text when FormattedText is enabled.
Another small improvement was to display the list after two characters have been typed.
Here's the relevant code for anyone interested. -----------------------------------------------------------------------------------------------------------------------------------------------------
Private Sub OnInput_ValueChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles uxInput.ValueChanged If uxInput.TextLength = 1 Then Exit Sub _suggestionList.Clear() If Not String.IsNullOrEmpty(uxInput.Text) Then For Each row As String In _fullList If row.ToLower.Contains(uxInput.Text.ToLower) Then _suggestionList.Add(FormatString(row, uxInput.Text)) End If Next End If With uxSuggestionList .DataBind() '_suggestionList is the datasource. When it's rebuilt we need to reset databinding. .DisplayLayout.UIElement.VerifyChildElements() 'See http://news.infragistics.com/forums/p/7670/31953.aspx for explanation of this line. .DisplayLayout.Bands(0).Columns(0).PerformAutoResize() End With End Sub
Private Function FormatString(ByVal fullString As String, ByVal partToFormat As String) As String FormatString = Regex.Replace(fullString, partToFormat, New MatchEvaluator(AddressOf MatcherHandler), RegexOptions.IgnoreCase) End Function Private Function MatcherHandler(ByVal m As Match) As String Return "<b>" & m.Value & "</b>" End Function
Well, I'm not sure how dramatic it should be, but yes, it certainly will take more processing power to display formatted text than normal text. I don't think it matters if the text is actually formatted or not, it still has to draw in a compeltely different way.
Simply turning on FormattedText dramatically decreases the rendering and filtering speed of the grid even without applying any formatting strings. Does this seem right?
If you use FormattedText and set the Value of the cell to some XML string that indicates formatting, then this XML string is what would get saved to the data source by default. But you are right, there is a way to intercept this value on the fly and modify it. What you do is use a DataFilter. Check out the Infragistics KnowledgeBase for some sample DataFilters to see how they work. In this case you will want to handle the EditorToOwner and OwnerToEditor conversions.
Mike, thanks for the response. The only thing I need from the cell is if clicked to return the value to the textbox.
I assume I could write some code to build the xml on the fly then set the cell to it's value. Can you point me to some sample code?
Another thought, is there another control that may be able to accomplish the same thing? I'm simply looking to show a filtered list with the filter text highlighted in each of the results. The highlighting is the challenge given the app is a windows forms app. FYI, the highlighting idea comes from gmail. It does this when adding address in the To: line.