Solved

Bold Part of a String

Posted on 2008-10-04
4
788 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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
edit html 3 139
VB 2005 ClickOnce install - setup.exe gets an empty / blank error message... 3 77
error when i compile 5 715
Breakpoint problem 8 100
Programmer's Notepad is, one of the best free text editing tools available, simply because the developers appear to have second-guessed every weird problem or issue a programmer is likely to run into. One of these problems is selecting and deleti…
Here is a helpful source code for C++ Builder programmers that allows you to manage and manipulate HTML content from C++ code, while also handling HTML events like onclick, onmouseover, ... Some objects defined and used in this source include: …
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…
THe viewer will learn how to use NetBeans IDE 8.0 for Windows to perform CRUD operations on a MySql database.

808 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