I am having multiple problems with TAdvStringGrid. I wrote a demo application that demonstrates all these problems (attached at the bottom). The first problem (and most importantly to me) is that I need to word wrap and automatically adjust the height of the rows. Also, I am having problems with the width of the borders not being consistent. Finally, I am having problems getting cells to right justify.
Here is my best attempt to do the word wrapping and auto line height:
void __fastcall TForm2::FormCreate(TObject *Sender)
{
grdOldFormat->AutoSizeRows(true, 20);
grdOldFormat->RowCount = 5;
grdOldFormat->FixedCols = 0;
grdOldFormat->FixedRows = 0;
grdOldFormat->DefaultRowHeight = 40;
…
grdOldFormat->ColCount = 6;
}
//---------------------------------------------------------------------------
void __fastcall TForm2::grdOldFormatGetWordWrap(TObject *Sender, int ACol, int ARow,
bool &WordWrap)
{
WordWrap = true;
}
Here is what I have done for setting the border widths. I only want borders around certain pairs of cells, so there is a little bit of extra logic to avoid making pairs within the first and fourth rows. When I do this, some borders see to be missing or fewer pixels wide than specified. For example, if I use 1px Line width, there is no bottom or right line. If I pick 2px for Line width, it looks like the bottom and right are 1px wide and the top and left are 2px wide, etc.:
void __fastcall TForm2::grdOldFormatGetCellBorderProp(TObject *Sender, int ARow, int ACol,
TPen *LeftPen, TPen *TopPen, TPen *RightPen, TPen *BottomPen)
{
bool includeRight = false;
bool includeLeft = false;
int lineWidth = lstLineWidth->SelectedItemIndex + 1;
switch (cmbDispMode->ItemIndex) {
case 0:
if (ACol % 2 == 1) {
includeRight = true;
} else if (ACol == 0) {
includeLeft = true;
}
break;
}
if (includeRight) {
RightPen->Width = lineWidth;
RightPen->Style = TPenStyle::psSolid;
RightPen->Color = clBlack;
}
if (includeLeft) {
LeftPen->Width = lineWidth;
LeftPen->Style = TPenStyle::psSolid;
LeftPen->Color = clBlack;
}
TopPen->Width = lineWidth;
TopPen->Style = TPenStyle::psSolid;
TopPen->Color = clBlack;
BottomPen->Width = lineWidth;
BottomPen->Style = TPenStyle::psSolid;
BottomPen->Color = clBlack;
}
//---------------------------------------------------------------------------
void __fastcall TForm2::grdOldFormatGetCellBorder(TObject *Sender, int ARow, int ACol,
TPen *APen, TCellBorders &Borders)
{
switch (cmbDispMode->ItemIndex) {
case 0:
if ((ARow % 3) != 0) {
if (ACol % 2 == 1) {
Borders << cbRight << cbTop << cbBottom;
} else if (ACol == 0) {
Borders << cbLeft << cbTop << cbBottom;
} else {
Borders << cbTop << cbBottom;
}
}
break;
}
}
And here is what I’ve done to try to get every other column to right justify. When I do this, it does not do row #0 even though I specified “grdOldFormat->FixedRows = 0;” in the form create. Also, I have the cells all editable and the justification seems to be applied during the time the editing takes place, but after editing a cell, the cell goes back to the (sometimes incorrect) justification it had prior to editing the cell:
void __fastcall TForm2::grdOldFormatGetAlignment(TObject *Sender, int ARow, int ACol,
TAlignment &HAlign, TAsgVAlignment &VAlign)
{
if (ACol % 2 == 0) {
HAlign = taRightJustify;
}
}
There is also a separate issue, I'd appreciate an answer to is how to adjust the height of the text in the combobox on this demo. I don't know if I need to submit a separate request for that of if you could just help me there also.
Too use the attached demo, select a line width, then select a quantity of columns. Note the first row appears differently than the fourth row. All the text is editable, so you can test word wrapping.
ConfigBrowser.zip (6.0 KB)