Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
220
Highlight the part of the text in UltraGridCell
posted

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:

          //Get a reference to the cell
 
          aCell = (UltraGridCell)drawParams.Element.SelectableItem;
 
          aCell.Activation = Activation.ActivateOnly;
 

                 if (aCell.Value.ToString().Contains(ultraTextEditor1.Text.Trim()))
                 {
                     aCell.Style = Infragistics.Win.UltraWinGrid.ColumnStyle.FormattedText;
                                               
                     string formattedText = aCell.Text.Replace(ultraTextEditor1.Text.Trim().ToString(), "<b>" + ultraTextEditor1.Text.Trim() + "<b>");
                     aCell.Value = formattedText;
                }
             break;
          }
}

Please help me to overcome this problem..

Thanks

Manoj

 

 

Parents
No Data
Reply
  • 469350
    Suggested Answer
    Offline posted

    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.

Children