Hi ,
I m in need of highlighting a word or phrase in Ultrawingrid. Is it possible to do this. Currently I m using NetAdvantage for .NET 2007 Vol. 3 CLR 2.0.
Hi there,
Try this code to see if it does what you are looking for:
/// <summary>
/// Finds the phrase.
/// </summary>
/// <param name="g">The WinGrid reference.</param>
/// <param name="s">The string you want to look for.</param>
public static void FindPhrase(UltraGrid g, String s)
{
foreach (UltraGridRow r in g.Rows)
foreach (UltraGridCell c in r.Cells)
if (c.Text.Contains(s))
c.Activate(); //The Cell must be activated first
g.PerformAction(UltraGridAction.EnterEditMode); //Cell must be in Edit mode to perform a selection
c.SelStart = c.Text.IndexOf(s); //Start the Selection
c.SelLength = s.Length; //for this length
g.DisplayLayout.RowScrollRegions[0].FirstRow = r; //for eye candy, make this the first visible row
return;
}
Hi,
This enables us to highlight the first appearance of the text in the grid. How can we extend this to select all appearances of text in all records of the grid?
Unfortunately, this specific technique will only work with one cell (or in reality, text editor) at a time. You will not be able to have multiple text editors all in edit mode with text selected @ the same time. However, may I suggest that you take an approach similar to:
1. Iterate through the grid cells
2. Find each instance of your matching text
3. Alter the cell appearance for each of the instances that match your text (Set the background color or something similar)
However, this is not going to put the cells in edit mode and allow you to select actual text in the cell editor. This is more of an approach that allows you to show your end users what cells contain the matching text.
Alternately, you can also use "Conditional Formatting" to accomplish the same result. Here are some links to how you can implement conditional formatting to accomplish your goal:
http://help.infragistics.com/NetAdvantage/WinForms/2010.1/CLR2.0/?page=WinGrid_You_Can_Now_Conditionally_Format_Cells_in_a_WinGrid_Column_Whats_New_20071.html
http://help.infragistics.com/NetAdvantage/WinForms/2010.1/CLR2.0/?page=Win_Conditional_Formatting.html
http://help.infragistics.com/NetAdvantage/WinForms/2010.1/CLR2.0/?page=Win_WinGrid_Using_Conditional_Formatting.html
Thanks for the reply. But conditional formatting would not be ideal solution for this issue as I need to highlight or change text appearance of portion of cell text to bold that matches with search text.
Is there any way we can achieve it?
Thanks for your replies. That really works.
You don't actually need an editor for this, you can just set the Style on the column to FormattedText and it will use a FormattedTextEditor automatically.
The only down side to this approach is that it requires you to change the cell Value (and thus changes your data). So you might want to hide the "real" column of data and replace it with an unbound column so you can modify a copy of the value instead of the real thing.
Hi again,
You can achieve this type of behavior by using our WinFormattedTextEditor control and embedding it into your WinGrid columns.
One way to accomplish this is to set the Cell.Value property to a text string that contains markup that wraps the "found" word with the appropriate tags. See the following topics for:
Links to ALL WinFormattedTextEditor topics:
http://help.infragistics.com/NetAdvantage/WinForms/2010.1/CLR2.0/?page=WinFormattedTextEditor.html
Embedding the editor into WinGrid columns:
http://help.infragistics.com/NetAdvantage/WinForms/2010.1/CLR2.0/?page=WinFormattedTextEditor_Embedding_WinFormattedTextEditor_in_a_WinGrid_Column.html
Markup Tags used to format text:
http://help.infragistics.com/NetAdvantage/WinForms/2010.1/CLR2.0/?page=WinFormattedLinkLabel_Formatting_Text_and_Hyperlinks.html
I hope this brings you to your solution!
Thanks,
Tom