一、改变行颜色:在DBGrid的DrawColumnCell事件来改变行颜色
//
void __fastcall TForm1::dbgrd1DrawColumnCell(TObject *Sender,
const TRect &Rect, int DataCol, TColumn *Column,
TGridDrawState State)
{
if(qry1->RecNo%2==0)
{
Column->Color=clRed;
}
else
{
Column->Color=clBlue;
}
if(State.Contains(gdSelected))
Column->Color=clBlack;
}
此处的qry1是DBGrid控件dbgrd1的数据集,dbgrd1是DBGrid1控件,
qry1->SQL->Add("SELECT FNumber AS FFieldName,FName AS FEnDispLabel FROM t_Item where FItemClassID=100010");
二、得到当前DBGrid控件选中单元的各种属性值(当选中某个单元格的时候,qry1的标记会自动跳转到该条记录,也许执行了类似qry1->Next();的语句)
当前选中单元格行号: qry1->RecNo
当前选中单元格列号: dbgrd1->SelectedIndex
当前选中单元格内容:dbgrd1->SelectedField->Text
当前选中单元格内容列名:dbgrd1->SelectedField->DisplayLabel
选中单元格所在行的所有值:以我的为例:两个字段的值分别为qry1->FieldByName("FFieldName")->AsString和qry1->FieldByName("FEnDispLabel")->AsString;