Help with Higlighting partial string

Posted by: Victor.m.charles.civ on 26 January 2021, 9:59 am EST

    • Post Options:
    • Link

    Posted 26 January 2021, 9:59 am EST

    Hi,

    How do you modify the code below to also highlight partial string match?

    If C1AOP5(e.Row, e.Col) = FormGlobalMain.TextBox1.Text Then

    e.CellStyle.BackColor = Color.Red

    e.CellStyle.ForeColor = Color.White

    End If

    Thanks,

    Victor

  • Posted 27 January 2021, 4:26 am EST

    Hi,

    You need to do a custom drawing if you need to highlight the string match. You can use the OwnerDrawCell event of the TrueDbgrid to custom draw the cell contents, you need to first set the OwnerDraw property of all DisplayColumns to true, for the OwnerDrawCell event to fire. In the owner draw cell, you can use the MeasureCharacterRanges method to get the bounds of the match and then redraw the text after drawing the filled highlight rectangle for it. Please refer to the sample attached.

    For info on MeasureCharacterRanges, please visit :

    https://docs.microsoft.com/en-us/dotnet/api/system.drawing.graphics.measurecharacterranges?view=dotnet-plat-ext-5.0

    Regards,

    Prabhat Sharma.

    TDBHighlightSearch.zip

  • Posted 27 January 2021, 7:53 pm EST

    Hello,

    Is there a solution in VB.NET? Also is it possible to send me a sample application.

    Thanks,

    Victor

  • Posted 28 January 2021, 12:52 am EST

    Hi Victor,

    A VB.NET sample is attached with the previous reply. You can find it at the end of the previous reply, or you can use this link :

    https://gccontent.blob.core.windows.net/forum-uploads/file-22343370-146c-4d69-b09d-0e64deb7fc9b.zip

    Regards,

    Prabhat Sharma.

Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels