Page 1 of 1

Copying Table Cell Properties...

Posted: Mon Apr 30, 2007 12:08 am
by Shane Stump
I have allowed my users to create data 'tags' within a document template.

I also allow them to create 'data bands' via tables. The data band tables have a row of fields.

As I parse the document processing tags, when I get to a data set table, I insert RecordCount - 1 rows in the table to hold all the data in the data set.

I use the table's InsertRows() method and I specify the data field row as the row to copy the attributes to the inserted rows and it works as expected.

The problem I am having is that I need to copy the data set row's TEXT cell attributes also (vertical + horizontal alignment, color, font, etc).

What is the best way to do this?

Best Regards,

Shane

Posted: Mon Apr 30, 2007 9:48 am
by Sergey Tkachenko
You can use some undocumented methods:
table.Cells[Row,Col].AssignAttributesFrom(SourceCell, False, 1, 1);

Or, if you want this assignment to be undone, use table.AssignCellAttributes with the same parameters.

If the boolean parameter is False, BestWidth and BestHeight properties are not assigned. If it is True, it is assigned, divided by values of the two last parameters.

In both cases, only properties of cell are assigned. Content is not assigned.

Posted: Mon Apr 30, 2007 3:23 pm
by Shane Stump
Sergey,

I tried AssignAttributesFrom() and it doesn't copy the source cell's font or alignment properties. Please see C++ code below:

void TReservationDocumentEditDialog::InsertTableRows(TRVTableItemInfo * pTable,int nFieldRow,TDataSet * pDataSet,TOnDocumentProcessTags pOnProcessTags)
{
// Determine last data row
int nLastDataRow = nFieldRow + pDataSet->RecordCount - 1;

// Insert rows
if (nLastDataRow > nFieldRow)
{
pTable->InsertRows(nFieldRow + 1,pDataSet->RecordCount - 1,nFieldRow);
}

// Set alias to field row
TRVTableRow * pFieldRow = (*pTable->Rows)[nFieldRow];

// Copy original field values
for (int nDataRow = nFieldRow + 1; nDataRow <= nLastDataRow; ++nDataRow)
{
for (int nColIndex = 0; nColIndex < pFieldRow->Count; ++nColIndex)
{
TRVTableCellData * pSourceFieldCellData = pTable->Cells[nFieldRow][nColIndex];
TRVTableCellData * pTargetFieldCellData = pTable->Cells[nDataRow][nColIndex];
if (pSourceFieldCellData != NULL)
{
// Assign target attributes same as source field
pTargetFieldCellData->AssignAttributesFrom(pSourceFieldCellData,false,1,1);

// Set aliases to cell data objects
TCustomRVData * pSourceFieldRVData = pSourceFieldCellData->GetRVData();
TCustomRVData * pTargetFieldRVData = pTargetFieldCellData->GetRVData();

// Text item ??
if (pSourceFieldRVData->GetItemStyle(0) >= 0)
{
pTargetFieldRVData->SetItemTextA(0,pSourceFieldRVData->GetItemTextA(0));
}
}
}
}
}


Best Regards,

Shane

Posted: Wed May 02, 2007 1:49 pm
by Shane Stump
Sergey,

Any idea why the above code isn't working?

Best Regards,

Shane

Posted: Wed May 02, 2007 5:53 pm
by Sergey Tkachenko
Table.InsertRows already uses AssignAttributesFrom for copying cell properties to the inserted rows.
But only cell properties are copied, not cell content. New cells have one empty text item of 0 text style and 0 paragraph style.
Well, in the next update, styles of this text item will be copied too.

Posted: Thu May 03, 2007 3:51 am
by Shane Stump
Sergey.

Couple of Things:

1) Do you know when the next version will be out - approximately?

2) Do you have a short-term recommendation on how I can do this (what cell properties do I need to copy (call)?

3) Can you add an option in the next version to also save the page layout ?

Best Regards,

Shane

Posted: Thu May 03, 2007 4:33 pm
by Sergey Tkachenko
1) This week (update for registered users)
2)
NewCell->Clear();
NewCell->AddNLATag('', StyleNo, ParaNo);
where
ParaNo = SourceCell->GetItemPara(0);
StyleNo = index of style of the first text item in SourceCell (or 0, if this cell does not have text items)

3) What do you mean?

Posted: Thu May 03, 2007 4:37 pm
by Shane Stump
GREAT! Since I am a registered user, I will be happy!

3) What do you mean?
Save margins. I am trying to get some code you posted several months back to work now to save the margins!

Best Regards,

Shane

Posted: Thu May 03, 2007 5:10 pm
by Sergey Tkachenko
I do not want to save RVPrint's properties in RVF by default. Because page properties will be implemented differently in future versions.

Posted: Fri May 04, 2007 12:46 am
by Shane Stump
Sergey Tkachenko wrote:1) This week (update for registered users)
2)
NewCell->Clear();
NewCell->AddNLATag('', StyleNo, ParaNo);
where
ParaNo = SourceCell->GetItemPara(0);
StyleNo = index of style of the first text item in SourceCell (or 0, if this cell does not have text items)

3) What do you mean?
I will wait for the update for #2 as I need the entire target cell attributes to be copied and you know better than I do what all that means (meaning I have tried the suggestions and it is still incomplete).

Best Regards,

Shane

Posted: Sun May 06, 2007 9:53 am
by Sergey Tkachenko
New update is available for registered users. Copying default text and paragraph style for inserted rows/columns is implemented.

Posted: Sun May 06, 2007 3:06 pm
by Shane Stump
THanks!

Shane