TCRDBGrid: change column title may change caption

Discussion of open issues, suggestions and bugs regarding UniDAC (Universal Data Access Components) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
albourgz
Posts: 160
Joined: Wed 06 May 2009 12:17
Location: belgium

TCRDBGrid: change column title may change caption

Post by albourgz » Fri 09 Dec 2016 14:48

Hi,
unidac 6.4.16.
I have TUniQuery->TUniDataSource->tcrdbgrid, oracle dataset. The query is a simple select (no functions).
At design time I added Fields to query then to grid, and adjusted width in tcrdbgrid columns
Then removed fields from uniquery. Columns and widths are still right in grid.
I added this in AfterOpen event of the query:

Code: Select all

void __fastcall TFStock::QDictAfterOpen(TDataSet *DataSet)
{
//Title Grid Captions
    UnicodeString s;
    int i;
    int iLength[100];
    // save before open widths
    for (i=0; i<DBGridDict->Columns->Count; i++)
        iLength[i]=DBGridDict->Columns->Items[i]->Width;
    STRINGTYPE sQt=GDB->getCaption("CMSG_QUANTITY");
    // set all MinWidth to 0
    for (i=0;i<DBGridDict->Columns->Count;i++)
        DBGridDict->Columns->Items[i]->MinWidth=0;
    // change some titles or width
    i=0;
	DBGridDict->Columns->Items[i++]->Width=0;
	DBGridDict->Columns->Items[i++]->Title->Caption=GDB->getCaption("CMSG_DATE");
	DBGridDict->Columns->Items[i++]->Title->Caption=GDB->getCaption("CMSG_PRODUCT");
	DBGridDict->Columns->Items[i++]->Title->Caption=GDB->getCaption("CMSG_REFERENCE");
	DBGridDict->Columns->Items[i++]->Title->Caption=GDB->getCaption("CMSG_VERSION");
	DBGridDict->Columns->Items[i++]->Title->Caption=GDB->getCaption("CMSG_ORIGIN");
    if (!cbQt->Checked)
    	DBGridDict->Columns->Items[i]->Width=0;
    else
        DBGridDict->Columns->Items[i]->Width=40;
	DBGridDict->Columns->Items[i++]->Title->Caption=sQt;
	DBGridDict->Columns->Items[i++]->Title->Caption=GDB->getCaption("CMSG_MOVE");
	DBGridDict->Columns->Items[i++]->Title->Caption=GDB->getCaption("CMSG_DESTINATION");
    if (!cbQt->Checked)
    	DBGridDict->Columns->Items[i]->Width=0;
    else
        DBGridDict->Columns->Items[i]->Width=40;
	DBGridDict->Columns->Items[i++]->Title->Caption=sQt;
	DBGridDict->Columns->Items[i++]->Title->Caption=GDB->getCaption("CMSG_TRIGRAM");
    DBGridDict->Columns->Items[i++]->Title->Caption=GDB->getCaption("CMSG_UNITPRICE");
    DBGridDict->Columns->Items[i++]->Title->Caption=GDB->getCaption("CMSG_CURRENCY");
    DBGridDict->Columns->Items[i++]->Title->Caption=GDB->getCaption("CMSG_UNITPRICEEURO");
    DBGridDict->Columns->Items[i++]->Title->Caption=GDB->getCaption("CMSG_TOTALPRICEEURO");
    DBGridDict->Columns->Items[i++]->Title->Caption=GDB->getCaption("CMSG_REASON");
    DBGridDict->Columns->Items[i++]->Title->Caption=GDB->getCaption("CMSG_SUBREASON");
    DBGridDict->Columns->Items[i++]->Title->Caption="SN";
    DBGridDict->Columns->Items[i++]->Title->Caption=GDB->getCaption("CMSG_JOB");
    DBGridDict->Columns->Items[i++]->Title->Caption="AR";
    for (i=0; i<DBGridDict->Columns->Count; i++)
        // check width for columns where width has NOT been modified
        if (DBGridDict->Columns->Items[i]->Width>0 && DBGridDict->Columns->Items[i]->Width!=40)
            if (DBGridDict->Columns->Items[i]->Width!=iLength[i]) {
                s.cat_sprintf(L"old Length %d, new Length %d, column %s\n", iLength[i], DBGridDict->Columns->Items[i]->Width,
                    DBGridDict->Columns->Items[i]->FieldName);
                }
    if (s>"")
        ShowMessage(s);
}
At Runtime I get a message:
---------------------------
Gestion Interne
---------------------------
old Length 84, new Length 58, column UNITPRICEDEV
old Length 42, new Length 37, column CURUP
old Length 62, new Length 98, column UNITPRICE
old Length 71, new Length 68, column TOTALPRICE

---------------------------
OK
---------------------------
The only widths that are modified in after open are set to 0 or 40, not of one of the above.
So changing the width of a column in a grid has an influence on the with of the other columns. Why Why Why?

Query is

Code: Select all

SELECT A.ID AS THEID, A.ONDT, B.VERSION, B.NAME, C.NAME AS OrigSite, A.QTORIG, A.QTMOVE, D.NAME AS DestSite, A.QTDEST, E.TRIGRAMME,B.REFERENCE, A.BUYUP AS UNITPRICEDEV, A.CURUP, A.BUYUP*A.BUYDAYCOURSE AS UNITPRICE, A.BUYUP*A.BUYDAYCOURSE*A.QTMOVE AS TOTALPRICE, F.NAME AS REASON, G.NAME AS PROJECT, A.SENDNR, A.JOB, A.NO_REC, A.SITEDEST as Destination, A.UNMODIFYABLE 
FROM VSTOCKMOVES A, VPRODUCTS B, VSITES C, VSITES D, VEMPLOYEES E, VREASONS F, VPROJECTS G
WHERE B.ID=A.PRODUCT AND A.SITEORIG=C.ID AND A.SITEDEST=D.ID AND A.USERID=E.ID AND A.REASON=F.ID AND F.PROJECT=G.ID
 AND A.ONDT BETWEEN TO_DATE('2016-12-09', 'yyyy-mm-dd') AND TO_DATE('2016-12-10', 'yyyy-mm-dd')
ORDER BY A.ONDT, B.NAME

AlexP
Devart Team
Posts: 5530
Joined: Tue 10 Aug 2010 11:35

Re: TCRDBGrid: change column title may change caption

Post by AlexP » Tue 13 Dec 2016 11:27

Please provide the script of creating the table used in your sample.

Post Reply