WEB开发网
开发学院软件开发Delphi TAdvStringGrid控件使用技巧 阅读

TAdvStringGrid控件使用技巧

 2010-12-15 08:05:48 来源:WEB开发网   
核心提示:10.多行显示 bool TAdvStringGrid:: Multilinecells属性,是否支持多行显示,如果支持的话,TAdvStringGrid控件使用技巧(2),可以用”#13”作为分隔符插入多行字符串,用多行显示, 设置bool &canedit参数来达到能否编辑某些单元格的效果

  10.多行显示
  bool TAdvStringGrid:: Multilinecells属性,是否支持多行显示,如果支持的话,可以用”#13”作为分隔符插入多行字符串,用多行显示。
折中的方法,可以用WordWrap来支持多行显示
  一般在设置和取消多行显示时,同时,对TAdvStringGrid::DefaultRowHeight进行设置,将有良好的效果。

  11.欲设置某些行或列为Fixed风格的显示,使用OnIsFixedCell()事件句柄来处理,调用TAdvStringGrid:: Repaint()方法来使设置生效。
例如:
If(colfix->Checked) { //colfix为一个TCheckBox
AdvStringGrid1->Repaint();
}
//事件处理句柄
void __fastcall TForm1::AdvStringGrid1IsFixedCell(TObject *Sender,
int Arow, int Acol, bool &isfixed)
{
if ((Acol==3) && (colfix->Checked))
isfixed=TRUE; else isfixed=FALSE;
}

  12.处理显示风格,如添加货币前缀和物理量单位
  在TAdvStringGrid::OnGetFormat()事件处理句柄中处理。
aPrefix参数设置显示前缀;
aSuffix参数设置显示后缀;
AStyle参数enum TSortStyle { ssAutomatic, ssAlphabetic, ssNumeric, ssDate, ssAlphaNoCase, ssAlphaCase, ssShortDateEU, ssShortDateUS, ssCustom, ssFinancial, ssAnsiAlphaCase, ssAnsiAlphaNoCase, ssRaw, ssHTML, ssImages, ssCheckBox, ssUnicode };设置排序风格;

  13.是否能对特定的单元格进行编辑
用TAdvStringGrid::OnCanEit()事件句柄来处理,
设置bool &canedit参数来达到能否编辑某些单元格的效果

  14.隐藏和显示某些单元格
TAdvStringGrid:: UnHideColumn(int ACol)
TAdvStringGrid::HideColumn(int ACol);

  15.查找的实现:
TAdvStringGrid::Find()
TAdvStringGrid::FindNext();
两个方法返回TPoint类型,
Find()需要一个TFindParams类型的参数,enum TFindParameters { fnMatchCase, fnMatchFull, fnMatchRegular, fnDirectionLeftRight, fnMatchStart, fnFindInCurrentRow, fnFindInCurrentCol, fnIncludeFixed, fnAutoGoto, fnIgnoreHTMLTags, fnBackward, fnIncludeHiddenColumns };可通过自己设计一个查找窗体来实现。
例如:
//----------findfirst----------
void __fastcall TForm1::Findfirst1Click(TObject *Sender)
{
TFind *Find;
TFindParams findparams;
TPoint res;

Find = new TFind(Form1);

if (Find->ShowModal()==mrOk)
{
if (Find->chkcase->Checked) findparams << fnMatchCase;
if (Find->chkfull->Checked) findparams << fnMatchFull;
if (Find->chkregular->Checked) findparams << fnMatchRegular;
if (Find->dir->ItemIndex==1) findparams << fnDirectionLeftRight;
if (Find->where->ItemIndex==1) findparams << fnFindInCurrentCol;
if (Find->where->ItemIndex==2) findparams << fnFindInCurrentRow;

res = AdvStringGrid1->FindFirst(Find->findtext->Text,findparams);
if (res.x>=0)
{
AdvStringGrid1->Col=res.x;
AdvStringGrid1->Row=res.y;
}
else
ShowMessage("Text not found");
}
delete Find;
}
//----------findnext----------
void __fastcall TForm1::Findnext1Click(TObject *Sender)

上一页  1 2 3 4  下一页

Tags:TAdvStringGrid 控件 技巧

编辑录入:爽爽 [复制链接] [打 印]
赞助商链接