-
别人给的解答
2004-05-14
版权声明:转载时请以超链接形式标明文章原始出处和作者信息及本声明
http://coastline.blogbus.com/logs/175115.html
在 StringGrid1 的 OnDrawCell 事件中动态判断当前列各行数据的长度,再设置列宽。
void __fastcall TForm1::StringGrid1DrawCell(TObject *Sender, int ACol,
int ARow, TRect &Rect, TGridDrawState State)
{
AnsiString str = "";StringGrid1->Canvas->Font = StringGrid1->Font;
for(int r=0;r<StringGrid1->RowCount;r++)
if( StringGrid1->Cells[ACol][r].Length() > str.Length() )
str = StringGrid1->Cells[ACol][r];int colWidth = StringGrid1->Canvas->TextWidth(str) + 4;
if( colWidth > StringGrid1->ColWidths[ACol] )
StringGrid1->ColWidths[ACol] = colWidth;}
收藏到:Del.icio.us








评论