advstringgrid 使用.docx

上传人:b****5 文档编号:2798754 上传时间:2022-11-15 格式:DOCX 页数:16 大小:22.98KB
下载 相关 举报
advstringgrid 使用.docx_第1页
第1页 / 共16页
advstringgrid 使用.docx_第2页
第2页 / 共16页
advstringgrid 使用.docx_第3页
第3页 / 共16页
advstringgrid 使用.docx_第4页
第4页 / 共16页
advstringgrid 使用.docx_第5页
第5页 / 共16页
点击查看更多>>
下载资源
资源描述

advstringgrid 使用.docx

《advstringgrid 使用.docx》由会员分享,可在线阅读,更多相关《advstringgrid 使用.docx(16页珍藏版)》请在冰豆网上搜索。

advstringgrid 使用.docx

advstringgrid使用

advstringgrid使用

TAdvStringGrid是Delphi编程中常用的控件,经常用于统计数据和设计比较复杂的表格。

控件功能很强大,但相应的使用也很复杂!

  以下是我整理出的常用技巧,有一部分是我自己的经验,有一部分是网上搜的别人的总结,有一部分整理了,有一部分没有整理;有一部分测试了,有一部分没有经过测试~~~呵呵,但都是我手工编辑的啊~~。

(部分示例过程是用于创建和设置动态Cells的过程,如果不理解请参考我总结的另一篇文章<完美动态TAdvStringGrid(cells)一例>)

  常用属性设置

  --- 

Options—goEditing:

是否可以编辑

Options—goTabs:

控制是否可用TAB键将光标移到下一CELL

Option—goColSizing/RowSizing=true:

设置列宽/行高可调整

Navigation—AlwaysEdi=true:

进入单元格时自动变成编辑状态

Navigation—AdvanceOnEnter=true:

回车时自动移到下一个CELL

Navigation—AdvancelInsert:

控制当光标在最后一个CELL时是否可以按回车插入新行

Navigation—AllowDeleteRow:

控制是否按DELETE键删除当前行

Navigation—AppendOnArrowDown:

控制按下箭头是否可以新增一行(未找到这个属性)

MouseActions—RowSelect/ColSelect=true:

选择整行/选择整列

Navigation—AutoComboDropSize=true组合框下拉框展开宽度自动设置

MouseActions—DirectComboDrop=True组合框进入时自动展开

(点击鼠标时直接进入编辑,或允许、不允许改变行或列宽等特性,都可以在MouseActions中设置。

AutoNumAlign:

=True则数字类型数据在CELL里会自动右对齐

AutoNumberCol(n);自动在第n列按顺序显示数字,即1,2,3……

AutoSize:

=true:

自动设置列宽,不推荐使用,自动调整后,真的很难看。

EnableWheel:

=true:

一次滚动多行,EnableWheel:

=False时,一次滚动一行。

SearchFooter—Visible:

=TRUE时,会在ADVStringGrid的底部显示出搜索框(未找到属性)

FloatingFooter—Visible:

为TRUE时,即在ADVStringGrid底部显示求和列,要想让求和列显示小数,还需要将FloatFormat属性设置为:

%g(未找到属性)

(自动换行到新追回行:

必须在onCellValidate过程中执行strGrid.AddRow;可以同时加一些赋值语句。

(当合并行后,如果想使文字垂直居中,可以先设置ADVStringGrid的MultilineCells设置为True,然后在文字前面加#13换行来实行)

(改变固定列的显示样式:

ControlLook——FixedGradientFrom(起始色)——FixedGradientFrom(结束色)

  +++

  用过程设置相关属性

  ---

1,设定单元表各列是否可以编辑:

首先在设置属性:

Options—goEditing=true;然后,在CanEditCell事件中设定。

procedureTForm50.stgPartListCanEditCell(Sender:

TObject;ARow,ACol:

Integer;varCanEdit:

Boolean);

Var

I:

integer;

begin

if(stgPartList.cells[cC1Data_Flag,ARow]='')or(stgPartList.cells[cC1Data_Flag,ARow]='C')thenbegin

canEdit:

=false;

exit;

endelsebegin

forI:

=0tocColQty1dobegin

ifACol=Ithenbegin

ifstgPartList.cells[cC1Data_Flag,aRow]='C'thenCanEdit:

=false

elsebegin

ifcColProp1[I,1]='Y'thenCanEdit:

=true;//cColProp1:

列属性数组,下同

ifcColProp1[I,1]='N'thenCanEdit:

=False;

end;

end;

end;

end;

end;

2,设定单元表各列对齐方式:

在GetAlignment事件中设定。

procedureTForm1.strGrid1GetAlignment(Sender:

TObject;ARow,ACol:

Integer;varAAlignment:

TAlignment);

Var

I:

integer;

begin

//直接定义

{ifARow=0thenAAlignment:

=tacenter

elsebegin

caseAColof

0:

AAlignment:

=taRightJustify;

1:

AAlignment:

=taCenter;

//2:

AAlignment:

=taCenter;

3:

AAlignment:

=taRightJustify;

4:

AAlignment:

=taCenter;

6:

AAlignment:

=taCenter;

8:

AAlignment:

=taCenter;

9:

AAlignment:

=taCenter;

elseAAlignment:

=taLeftJustify;

end;

end;}

//用属性数组定义

ifARow=0thenAAlignment:

=taCenter

elsebegin

forI:

=0toxpColQty1-1dobegin

ifACol=Ithenbegin

//casestrToInt(xaColProp1[I,4])

ifxaColProp1[I,4]='C'thenAAlignment:

=taCenter;

ifxaColProp1[I,4]='L'thenAAlignment:

=taLeftJustify;

ifxaColProp1[I,4]='R'thenAAlignment:

=taRightJustify;

end;

end;

end;

{//以下代码不明,此过程没有HAlign,VAlign

HAlign:

=taCenter;

VAlign:

=vtaCenter;}

end;

 3,改变单元格的背景色,可在OnGetCellColor事件中写代码实行(前提需将FLAT设置为TRUE)/设定Grid颜色:

在GetCellColor事件中设定:

procedureTForm50.stgPartListGetCellColor(Sender:

TObject;ARow,

ACol:

Integer;AState:

TGridDrawState;ABrush:

TBrush;AFont:

TFont);

Var

I:

integer;

begin

{ifstgPList.Cells[cNCols1[3]-2,ARow]='1'then

abrush.Color:

=clScrollBar

elsebegin

if(ARow=0)or(ACol=0)then

abrush.Color:

=clBtnFace

elsebegin

ifACol=cNCols1[2]-2then

abrush.Color:

=clwindow

else

abrush.Color:

=clinfoBK;

end;

end;}

ifARow=0then

abrush.Color:

=clBtnFace

elsebegin

forI:

=0tocColQty1dobegin

ifACol=Ithenabrush.Color:

=StringToColor(cColProp1[I,5]);

end;

end;

{ifARow=0thenbegin//如果不加这一句,则是以下对应的整列,我这里是只改变固列,所以要把ARow设为0

CaseAColof

1:

ABrush.Color:

=RGB(227,249,248);

2:

ABrush.Color:

=RGB(250,232,193);

3:

ABrush.Color:

=RGB(227,249,248);

4:

ABrush.Color:

=RGB(250,232,193);

12:

ABrush.Color:

=RGB(227,249,248);

14:

ABrush.Color:

=RGB(250,232,193);

24:

ABrush.Color:

=RGB(227,249,248);

48:

ABrush.Color:

=RGB(250,232,193);

51:

ABrush.Color:

=RGB(227,249,248);

End;

END;}

end;

  4,设置Grid中列特殊类型,某一列的数据格式,预定义的格式有:

  enumTEditorType{edNormal,edSpinEdit,edComboEdit,edComboList,edEditBtn,edCheckBox,edDateEdit,edDateEditUpDown,edTimeEdit,edButton,edDataCheckBox,edNumeric,edPositiveNumeric,edFloat,edCapital,edMixedCase,edPassword,edUnitEditBtn,edLowerCase,edUpperCase,edFloatSpinEdit,edTimeSpinEdit,edDateSpinEdit,edNumericEditBtn,edFloatEditBtn,edCustom,edRichEdit,edNone,edUniEdit,edUniComboEdit,edUniComboList};

  通过OnGetEditorType()事件进行设置,例如:

procedureTForm1.strGrid1GetEditorType(Sender:

TObject;ACol,ARow:

Integer;varAEditor:

TEditorType);

  switch(aCol)

    case1:

aEditor=edComboList;break;  //设置第一列为ComboBox类型输入

    case2:

aEditor=edEditBtn;break;  //设置第二列为EditBtn类型输入,弹出一个选择框

    case3:

aEditor=edSpinEdit;break;  //设置第三列为SpinEdit类型输入

    case4:

aEditor=edDa

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 工程科技 > 能源化工

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1