Board index » delphi » Changing Font Color and Size in DBGrid

Changing Font Color and Size in DBGrid

Hello,

Does anybody knows how to change the font color and size of the selected
row in a DBGrid ??

Thank you

Diego Irrazabal

 

Re:Changing Font Color and Size in DBGrid


  I need something similar, I want to change the color of a subitem in a
TListView component.   But just for that field, and just for that row.  If I
change the TListView.Font, all lines get changed.   Any ideas?

Quote
"Diego Irrazabal" <diego_irraza...@hotmail.com> wrote in message

news:3BAFAA37.C81D544D@hotmail.com...
Quote
> Hello,

> Does anybody knows how to change the font color and size of the selected
> row in a DBGrid ??

> Thank you

> Diego Irrazabal

Re:Changing Font Color and Size in DBGrid


Me too! I have the same problem. I want to change the style of a item in a ListBox component, but the changing the TListBox.font.style all items get changes.. have you an answer?

Quote
"Idel Lopez" <Idel.Lo...@Bigfoot.com> wrote:
>  I need something similar, I want to change the color of a subitem in a
>TListView component.   But just for that field, and just for that row.  If I
>change the TListView.Font, all lines get changed.   Any ideas?

>"Diego Irrazabal" <diego_irraza...@hotmail.com> wrote in message
>news:3BAFAA37.C81D544D@hotmail.com...
>> Hello,

>> Does anybody knows how to change the font color and size of the selected
>> row in a DBGrid ??

>> Thank you

>> Diego Irrazabal

Re:Changing Font Color and Size in DBGrid


Hi Aleesio,

Quote
> Me too! I have the same problem. I want to change the style of a item

in a ListBox component, but the changing the TListBox.font.style all
items get changes.. have you an answer?

Set the Style property to lbOwnerDrawFixed, and assign the Font.Style in
the OnDrawItem event (there is an example in the online help that should
help you, even if it is not changing the Font property).

Thrse

Re:Changing Font Color and Size in DBGrid


Hi Thrse
I thank you, but I have a problem too.
First of all I want to say that I'm Italian and I speak English not very well.
I try to make what you said. I don't understand what do you want to say with "assign the Font.Style in the OnDrawItem event". I have to set a new procedure? If I do this the listbox goes in loop as it is always drawing... How can I do?? Please answer me. Bye.

Quote
"Thrse Hanquet" <therese.hanq...@skynet.be> wrote:
>Hi Aleesio,

>> Me too! I have the same problem. I want to change the style of a item
>in a ListBox component, but the changing the TListBox.font.style all
>items get changes.. have you an answer?

>Set the Style property to lbOwnerDrawFixed, and assign the Font.Style in
>the OnDrawItem event (there is an example in the online help that should
>help you, even if it is not changing the Font property).

>Thrse

Re:Changing Font Color and Size in DBGrid


Alessio,

Quote
> I try to make what you said. I don't understand what do you want to

say with "assign the
Quote
> Font.Style in the OnDrawItem event". I have to set a new procedure? If

I do this the listbox
Quote
> goes in loop as it is always drawing... How can I do?? Please answer

me. Bye.

The OnDrawItem is an event that is generated when the TListBox has a
owner drawn style by the such as lbOwnerDrawFixed or
lbOwnerDrawVariable. It is generated for each element in the list.

In order to use it, you select the ListBox in the IDE and go to the
Events thumb, and double-click on "OnDrawItem". Delphi will create a
procedure that will be called each time the ListBox will have to draw an
element of the list (the different elements are identified by the Index
parameter). You will have to fill it with your own drawing code.

For example, let us say you want the 3d element in the list to be in
bold and the other ones in normal characters. This will give you
something like this:

procedure TMyForm.MyListBoxDrawItem(
  Control: TWinControl; Index: Integer; Rect: TRect;
  State: TOwnerDrawState);

begin

 with MyListBox.Canvas do
  begin
  if Index = 2 then Font.Style := [fsBold] else Font.Style := [];
  TextOut(Rect.Left, TheRect.Top, Items[Index]);
  end;

end;

Thrse

Re:Changing Font Color and Size in DBGrid


Sorry for the typo, should have been:

Quote
>   TextOut(Rect.Left, Rect.Top, Items[Index]);

Thrse

Other Threads