Hi
Please find below the code which i am using to highlight the part of the text in the UltraGridCell at runtime based on the text entered in the TextEditor, below code works fine for strings, but when i type in integer 1 in the texteditor i am getting an error "Cannot convert string to Integer"
As far as my knowledge goes in the below code since i am using Replace() with the html code in it, i assume this is not able to convert to integer which is why i get the error..
public bool DrawElement(DrawPhase drawPhase, ref UIElementDrawParams drawParams){ UltraGridCell aCell; Font font = this.ultraGrid1.Font; switch (drawPhase) { case DrawPhase.AfterDrawForeground:
Please help me to overcome this problem..
Thanks
Manoj
Hi Manoj,
I'm a little puzzled by what you are doing here. Setting properties on the cell inside a DrawFilter is probably not a good idea. It's certainly not very efficient. It seems like you should be setting properties like Activation, Style, and Value of the cell inside the InitializeLayout or InitializeRow events.
But this code will not work correctly in any case, for a couple of reason. First, you are trying to set the Value of an integer cell to a string and that won't work. Second, because you are losing the original value of the cell. If this code fires twice you will end up added addition bold tags to it every time, and you will never clear these tags.
What I would do is hide your integer column with the "real" value in it and then display an unbound string column to the user. I would use the InitializeRow event to get the value of the real column, convert it into a string, modify it however you like, and the set the Value on the unbound column.
Hello Mike,
Thanks for the reply...Its my mistake i did not remove the lines like Activation and style for the code, i agree it has to be in InitializeRow...
Many of the article says we can achieve highlighting the Text using simple FormattedText., so i was experimenting using FormattedText,
For instance i have a ID columns with values
ID
123
1235
1234556
say i want to format the text in the column to change the appearance of the digit 55 to bold using Formatted Text..
if you can please provide the sample for highlighting the text for the integer column it would be really helpful..
If you wanted the grid cell to display "1234556", which the "55" in bold, then you would have to use a String column in the grid. You can't do this with an integer column. So like I said, what I would do is use an unbound column. The code might look something like this:
private void ultraGrid1_InitializeLayout(object sender, Infragistics.Win.UltraWinGrid.InitializeLayoutEventArgs e) { // Hide the "real" data column e.Layout.Bands[0].Columns["Int32 1"].Hidden = true; // Add an unbound column UltraGridColumn formattedColumn = e.Layout.Bands[0].Columns.Add("Formatted Int32 1"); formattedColumn.DataType = typeof(string); formattedColumn.Style = Infragistics.Win.UltraWinGrid.ColumnStyle.FormattedText; formattedColumn.Header.Caption = "Int32 1"; } private void ultraGrid1_InitializeRow(object sender, InitializeRowEventArgs e) { // Make sure the unbound column exists. if (e.Row.Band.Columns.Exists("Formatted Int32 1")) { // Get hte int value from the Int32 1 column. int realValue = (int)e.Row.Cells["Int32 1"].Value; // Build a formatted string for the text and apply it to the unbound column. string formattedText = realValue.ToString().Replace("55", "<b>55</b>"); e.Row.Cells["Formatted Int32 1"].Value = formattedText; } }
Hi Mike,
Thanks for the reply...
Following is my concern on implementing this (highlight of test) using the unbound columns
1. There might be a scenatio where the number columns may be more (say 5, 10....) so for each column of type integer we have to create a unbound column then hide the original columns making the new unbound column visible, and this will not be dynamic.....
2. And in future when ever there will be changes to remove or add a new column then all the time we need to change this piece of code which is not a good idea....
So what i have done is (nothing gr8 though) but slightly tweaked
i am creating the new dataset with the columns similar to a original dataset and importing the rows to the newly created dataset, so when i add a columns to the new dataset all the columns will be of type string..
and then i am formatting the column in the similar way as mentioned above (FYR: the below code)
// Build a formatted string for the text and apply it to the unbound column. string formattedText = realValue.ToString().Replace("55", "<b>55</b>");
e.Row.Cells["Formatted Int32 1"].Value = formattedText;
And this works fine..!!! Which is finally what is needed...and it solves my above two concerns... :)
Please let me know ur thoughts....
The down side of doing it that way is the when you sort, filter, or use a summary in the grid, the values will all be treating as strings. So numbers won't sort properly, you won't be able to perform mathematical calculations without converting from the string first, and you won't get any built-in validation of the values in any editable cells.
Of course, all of these issues would exist with unbound columns, as well, but they would be easier to work around with things like SortComparers.
Thanks..
Yeah correct, things like sort, filter might not behave correctly on the numbers columns which
is treated as strings...
Regards
Hi,
As far as I know, there's no superscript or subscript functionality in the FormattedText support. I assume <sup> is an html tag? We don't actually use html, although our custom format is similar. So that tag probably isn't supported if it's not working.
Hi,Is there any way to add a superscript in Ultragrid cell. My need is to add a alphabet superscript in ultragrid cell. I have tried the <sup>text</sup> tag as we have used <b>text</b> tag in above example.
<b></b> tag is working fine. But <sup></sup> tag is not working. Is there any other tags present to achieve this. Please help.
eg. Sample TextM
Thanks in advance.
I don't see any easy way to handle so complex a case. You probably have to string out the escape codes first, then applying your formatting, and then put them back in. Or write your own Replace method that skips over the appropriate codes.
Here's a list of codes that are escaped by the EscapeXML method.
& = &
< = <
> = >
" = "
The above code seems like not working..Please find the example below & the snapshot for your reference.
1. The original Text before highlighting the character 'P' in the text
Original Text : SYBIL H. POLLET & MICHAEL N. POLLET, TIC
2. After escaping the Original Text using below code, the & is replaced with &as shown below
Infragistics.Win.FormattedLinkLabel.ParsedFormattedTextValue.EscapeXML(OriginalText)
Escaped XML: SYBIL H. POLLET & MICHAEL N. POLLET, TIC
3. At the time of formatting the escaped text, the formatting is also applied for the character 'P' in & as shown below, which supposed to be incorrect
Formatted Text: SYBIL H. <b>P</b>OLLET &am<b>P</b>; MICHAEL N. <b>P</b>OLLET, TIC
4. Please find the result that is shown in the grid after formatting the cell text.
Please help me with this..
Tried with the above code..It works fine... :)
Thanks a ton.... :)