Solved

Bold Part of a String

Posted on 2008-10-04
4
785 Views
Last Modified: 2013-11-23
I have a DBGrid1 and I am trying to bold part of a string in a field. For example I have HelloWorld, and I want to bold out the Hello part of it and leave the world part normal. How would I do this?
0
Comment
Question by:illfusion82
  • 3
4 Comments
 
LVL 14

Expert Comment

by:SteveBay
ID: 22642229
Here is an example of how to Bold the First Letter of each cell. You should be able to take this logic and expand it to match your needs
procedure TForm1.DBGrid1DrawColumnCell(Sender: TObject; const Rect: TRect;  DataCol: Integer; Column: TColumn; State: TGridDrawState);

begin

    With Sender As TDBGrid Do

      Begin

      Canvas.FillRect(Rect) ;

      Canvas.Font.Style := Canvas.Font.Style - [fsBold];

      Canvas.TextOut(Rect.Left + Font.Size , Rect.Top + 2 , DBGrid1.DataSource.DataSet.Fields[DataCol].AsString ) ;

      Canvas.Font.Style := Canvas.Font.Style + [fsBold];

      Canvas.TextOut(Rect.Left + Font.Size , Rect.Top + 2 , DBGrid1.DataSource.DataSet.Fields[DataCol].AsString[1] ) ;

      End ;

end;

Open in new window

0
 
LVL 14

Expert Comment

by:SteveBay
ID: 22642248
Almost forgot...
You need to set DefaultDrawing := False on the DBGrid and the code above goes in a OnDrawColumnCell
0
 
LVL 1

Author Comment

by:illfusion82
ID: 22651559
Hello SteveBay. Thanks for the code. Now is there a way to type in an TEdit field and have the letters I am typing in the TEdit field to bold out the letters in a single column. The code you gave me bolds out the first character in all columns. Kind of like the way Mozilla firefox uses autocomplete in their address field. When a user types in Mozilla Firefoxes address field it automatically bolds the letters that are being typed in the address field.
0
 
LVL 14

Accepted Solution

by:
SteveBay earned 500 total points
ID: 22652003
You can determine which column it is with DataSource.DataSet.Fields[DataCol].FieldName

You would need to parse out the string contained in:
DBGrid1.DataSource.DataSet.Fields[DataCol].AsString
and draw the separated parts with different fonts.

You can find the substring within a string using pos function.

You can determine the starting locations in Textout using Canvas.TextWidth.

This is mostly a new question. I would suggest posting a detailed request in a new question and perhaps I or someone else will supply detailed source.
0

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Suggested Solutions

Update (December 2011): Since this article was published, the things have changed for good for Android native developers. The Sequoyah Project (http://www.eclipse.org/sequoyah/) automates most of the tasks discussed in this article. You can even fin…
How to install Selenium IDE and loops for quick automated testing. Get Selenium IDE from http://seleniumhq.org (http://seleniumhq.org) Go to that link and select download selenium in the right hand columnThat will then direct you to their downlo…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
The viewer will learn how to use and create keystrokes in Netbeans IDE 8.0 for Windows.

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now