bcb新手,还有很多地方需要学习提升的,有不对的地方请提出来。
StringGird控件的基本设置
stringgrid1->ColCount = 6;//设置stringgrid1总列数
stringgrid1->RowCount = 4;//设置stringgrid1总行数
stringgrid1->FixedCols = 0;//设置stringgrid1资料区列数
stringgrid1->FixedRows = 1;设置stringgrid1资料区行数
个人理解:资料区是写表头的单元格,此处我只需要一行资料区。
stringgrid1->Cells[col][row]="欲显示的内容";//设置相应单元格的内容
stringgrid1->Color = clBlue;//设置stringgrid1颜色
stringgrid1->FixedColor = clYellow;//设置stringgrid1资料区颜色
然后需要实现选中一行的时候当前选中行背景颜色和字体颜色设置为其他颜色,网上搜了很多代码,c++的有点少,自己作个记录。
void __fastcall TForm1::stringgrid1DrawCell(TObject *Sender, int ACol,
int ARow, TRect &Rect, TGridDrawState State)
{
if(State.Contains(gdSelected))//判断选中状态
{
stringgrid1->Canvas->Brush->Color = RGB(119, 34, 85);//设置选中行背景颜色
stringgrid1->Canvas->F