Stringgrid header and columns

1) How to set text in a column header?

2) My grid has five columns. When I run the program, five columns are shown, but the 
fifth one is blank.

{code}
grid1.AddObject(TStringColumn.Create(self));
grid1.AddObject(TStringColumn.Create(self));
grid1.AddObject(TStringColumn.Create(self));
grid1.AddObject(TStringColumn.Create(self));

//grid1.Columns[0].Width := 0;
grid1.Cells[0,0] := 'Rec ID';
grid1.Cells[1,0] := 'Application';
grid1.Cells[2,0] := 'User ID';
grid1.Cells[3,0] := 'Password';
grid1.Cells[4,0] := 'Comment';

Thanks, Mike
0
Mike
10/1/2011 10:34:21 PM
embarcadero.delphi.firemonkey 4901 articles. 4 followers. Follow

5 Replies
18071 Views

Similar Articles

[PageSpeed] 57
Get it on Google Play
Get it on Apple App Store

There's a THeader component (in the grid palette) to which it appears you add THeaderItem sub-components at design time.

But if you actually want to use Row 0, you can still add TGridColums at design time.  I did that and was able to add pseudo-headers without a problem.
-2
Ian
10/2/2011 10:38:45 AM
On 10/2/2011 6:38 AM, Ian Trackman wrote:
> There's a THeader component (in the grid palette) to which it appears you add THeaderItem sub-components at design time.

It won't go outside the grid, so it can't be placed above the columns, but will cover 
a row. Also, AFAICS, you can't use it to resize the columns

There is a ShowHeader grid property that displays/hides a gradient bar. It is 
segmented to match the column width, and the cols can be resized with it.
>
> But if you actually want to use Row 0, you can still add TGridColums at design time.  I did that and was able to add pseudo-headers without a problem.

Row 0 is the first row, why would I not use it? How did you implement it so it 
matched the grid?

Any thoughts why the text 'Comments' doesn't appear?

This grid is certainly.......... different.
0
Mike
10/2/2011 12:08:52 PM
On 10/2/2011 8:08 AM, Mike Reublin wrote:
> This grid is certainly.......... different.

Maybe there's a reason it isn't on the component demo. . . . <BG>
1
Mike
10/2/2011 1:21:12 PM
Ian Trackman wrote:

> There's a THeader component (in the grid palette) to which it appears
> you add THeaderItem sub-components at design time.
> 
> But if you actually want to use Row 0, you can still add TGridColums
> at design time.  I did that and was able to add pseudo-headers
> without a problem.

My test TStringGrid has 3 columns and 4 rows .. and includes a header.

I have no problem adding/changing the text in my right-most cell[2,0]
as follows:
	StringGrid1.Cells[2,0] := 'Test';
but that is not in the header, it is the top row of the body.

To add/change the text in my header's right-most column, I am using:
	StringColumn3.Header := 'Col 3'; 

Malcolm
0
Malcolm
10/2/2011 2:28:02 PM
On 10/2/2011 10:28 AM, Malcolm Taylor wrote:
> Ian Trackman wrote:
>
>> There's a THeader component (in the grid palette) to which it appears
>> you add THeaderItem sub-components at design time.
>>
>> But if you actually want to use Row 0, you can still add TGridColums
>> at design time.  I did that and was able to add pseudo-headers
>> without a problem.
>
> My test TStringGrid has 3 columns and 4 rows .. and includes a header.
>
> I have no problem adding/changing the text in my right-most cell[2,0]
> as follows:
> 	StringGrid1.Cells[2,0] := 'Test';
> but that is not in the header, it is the top row of the body.

I wasn't adding enough columns. I was looking at the part of the "undergrid" that was 
showing to the right of the cols I had added.
>
> To add/change the text in my header's right-most column, I am using:
> 	StringColumn3.Header := 'Col 3';

YES! grid1.Columns[0].Header := 'Rec ID';
>
> Malcolm

Thanks, Malcolm
-1
Mike
10/2/2011 3:14:17 PM
Reply: