Center table.col

General TRichView support forum. Please post your questions here
Post Reply
j&b
Posts: 184
Joined: Mon Sep 05, 2005 1:35 pm

Center table.col

Post by j&b »

Hello

This sample clears table-columns (is oK).

I want to set table-columns (3 to 6) to center, left or right.
What's to do ? (important lines are 24, 25 and 28!! ).


Jürgen



//6spaltige Tabelle - Spalten 3 bis 6 sollen zentriert,linksbündig oder rechtsbündig formatiert werden

1 procedure TForm1.Button1Click(Sender: TObject);
2 var r,c, itemNo,data, styleNo,paraNo, v,b: integer;
3 s: string;
4 item: TCustomRVItemInfo;
5 begin
6
7 if (not memo.GetCurrentItemEx(TRVTableItemInfo, rve, TCustomRVItemInfo(rveTable))) then begin
8 ShowMessage('Es wurde keine Tabelle gewählt!');
9 exit;
10 end;
11
12 try
13 memo.GetCurrentItemEx(TRVTableItemInfo, rve, item);
14 ItemNo := memo.GetItemNo(rveTable);
15 memo.BeginItemModify(ItemNo, Data);
16 anzSpa_rve:= rveTable.Rows[0].Count;
17
18 s:=''; v:=2; b:=5; //Spalten 3 bis 6
19
20 for r := 0 to rveTable.Rows.Count-1 do begin
21 for c:=v to b do begin
22 if rveTable.Cells[r,c]<>nil then begin
23 if (rveTable.Cells[r,c].GetRVData.GetItemStyle(0)>=0) then begin

24 StyleNo := rveTable.Cells[r,c].GetRVData.GetItemStyle(0); //übernimmt bestehende Formatierung
25 ParaNo := rveTable.Cells[r,c].GetRVData.GetItemPara(0);

26 //s:=rveTable.Cells[r,c].GetRVData.GetItemTextA(0); //übernimmt Zellinhalt
27 rveTable.Cells[r,c].clear;


28 rveTable.Cells[r,c].AddNL('',StyleNo,ParaNo); //Zelle muss belegt werden, aber ... (siehe 24, 25)


29 //rveTable.Cells[r,c].AddNL(s,StyleNo,ParaNo); //übergibt Zellinhalt + übernimmt bestehende Formatierung
30 s:='';
31 end;
32 end;
33 end;
34 end;
35
36 finally
37 if rveTable<>nil then begin
38 memo.EndItemModify(ItemNo, Data);
39 memo.Change;
40 end;
41 end;
42 end;
j&b
Posts: 184
Joined: Mon Sep 05, 2005 1:35 pm

Re: Center table.col

Post by j&b »

I think I have found a solution:


24 StyleNo := rveTable.Cells[r,c].GetRVData.GetItemStyle(0); //übernimmt bestehende Formatierung
25 //ParaNo := rveTable.Cells[r,c].GetRVData.GetItemPara(0);
// 0: ganz links, 1: zentriert, 2: links mit Abstand ?: right

28 rveTable.Cells[r,c].AddNL('',StyleNo,1);


Does something know the Parameter of right-alignment ?
Last edited by j&b on Sun Apr 06, 2008 10:10 am, edited 1 time in total.
Sergey Tkachenko
Site Admin
Posts: 17559
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

I'll create an example when I return (after April, 13)
j&b
Posts: 184
Joined: Mon Sep 05, 2005 1:35 pm

Post by j&b »

Hello Sergey,

do you mean something like this ?

procedure TForm1.sbTesten1Click(Sender: TObject);
var i: integer;
begin
if query1.state in [dsEdit, dsInsert] then query1.post;
if (not memo.GetCurrentItemEx(TRVTableItemInfo, rve, TCustomRVItemInfo(rveTable))) then begin
showMessage('Geht nicht !'+#10+'Tabelle muss den Fokus besitzen.');
exit;
end;
try
for i:= 2 to 5 do begin
if i<>1 then begin
rveTable.SelectCols(i,1); //1 eine Spalte zur Zeit markieren
FontSize:= 9; memo.ApplyStyleConversion(rv_APPLYFONTSIZE);
SetAlignmentToUI(rvaRight); memo.ApplyParaStyleConversion(PARA_ALIGNMENT);
end;
end;
except
end;
memo.deselect;
end;
Sergey Tkachenko
Site Admin
Posts: 17559
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

Sorry, do you need to implement this as an editing operation (that can be undone by user) or not?
For an editing operation, your code is correct: select the proper cells and call ApplyParaStyleConversion.
j&b
Posts: 184
Joined: Mon Sep 05, 2005 1:35 pm

Post by j&b »

Hello Sergey,
thank you that you promise to your holding.
I use the above code.

Jürgen
Post Reply