Solved

Bold Part of a String

Posted on 2008-10-04
4
790 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
eclipse error 7 108
java class in read only mode in eclipse 2 168
Eclipse insufficient memory error 3 119
Resharper CTRL+N: Differentiate between files with same name 2 75
In our object-oriented world the class is a minimal unit, a brick for constructing our applications. It is an abstraction and we know well how to use it. In well-designed software we are not usually interested in knowing how objects look in memory. …
How to install Selenium IDE and loops for quick automated testing. Get Selenium IDE from http://seleniumhq.org Go to that link and select download selenium in the right hand columnThat will then direct you to their download page.From that page s…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
The viewer will learn how to use NetBeans IDE 8.0 for Windows to connect to a MySQL database. Open Services Panel: Create a new connection using New Connection Wizard: Create a test database called eetutorial: Create a new test tabel called ee…

726 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