search
HomeDatabaseMysql TutorialAdvStringGrid使用方法(2)

procedureTForm1.FormCreate(Sender:TObject); begin AdvStringGrid1.FixedRows:=2; AdvStringGrid1.SaveFixedCells:= false ; AdvStringGrid1.MergeCells(1,0,2,1); AdvStringGrid1.MergeCells(3,0,2,1); AdvStringGrid1.Cells[1,0]:= 'palign="center"bIde

  1. procedure TForm1.FormCreate(Sender: TObject);
  2. begin
  3.   AdvStringGrid1.FixedRows:=2;
  4.   AdvStringGrid1.SaveFixedCells := false;
  5.   AdvStringGrid1.MergeCells(1,0,2,1);
  6.   AdvStringGrid1.MergeCells(3,0,2,1);
  7.   AdvStringGrid1.Cells[1,0] := '

     Identification

    '
    ;
  8.   AdvStringGrid1.Cells[1,1] := 'Brand';
  9.   AdvStringGrid1.Cells[2,1] := 'Type';
  10.   AdvStringGrid1.Cells[3,1] := 'CC';
  11.   AdvStringGrid1.Cells[4,1] := 'Pk';
  12.   AdvStringGrid1.Cells[3,0] := '

    Power

    '
    ;
  13.   AdvStringGrid1.BtnEdit.ButtonWidth := 24;
  14. end;
 一、Navigation——AdvancelInsert:控制当光标在最后一个CELL时是否可以按回车插入新行

二、Navigation——AdvanceOnEnter:控制按回车是否自动移到下一个CELL

三、Navigation——AllowDeleteRow:控制是否按DELETE键删除当前行

四、Navigation——AppendOnArrowDown:控制按下箭头是否可以新增一行

五、EnableWheel:=true时,一次滚动多行,EnableWheel:=False时,一次滚动一行。

六、SearchFooter—Visible:=TRUE时,会在ADVStringGrid的底部显示出搜索框

七、Options—goTabs:控制是否可用TAB键将光标移到下一CELL

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

九、ADVStringGrid.AutoNumberCol(0);表示第0列按顺序显示数字,即1,2,3……

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

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

十二、改变固定列的显示样式:ControlLook——FixedGradientFrom(起始色)——FixedGradientFrom(结束色)

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

  1. procedure Tfrm_dingdan.strgridGetCellColor(Sender: TObject; ARow, 
  2.   ACol: Integer; AState: TGridDrawState; ABrush: TBrush; AFont: TFont); 
  3. begin 
  4.   if ARow=0 then     //如果不加这一句,则是以下对应的整列,我这里是只改变固列,所以要把ARow设为0 
  5.     begin 
  6.       Case ACol of 
  7.         1: ABrush.Color:=RGB(227,249,248); 
  8.         2: ABrush.Color:=RGB(250,232,193); 
  9.         3: ABrush.Color:=RGB(227,249,248); 
  10.         4: ABrush.Color:=RGB(250,232,193); 
  11.         12: ABrush.Color:=RGB(227,249,248); 
  12.         14: ABrush.Color:=RGB(250,232,193); 
  13.         24: ABrush.Color:=RGB(227,249,248); 
  14.         48: ABrush.Color:=RGB(250,232,193); 
  15.         51: ABrush.Color:=RGB(227,249,248); 
  16.       End; 
  17.     END; 
  18. end; 

十四、如果在录入的过程中,要对某列做格式化,比如保留几位小数,可用ADVStringGrid的GetFloatFormat事件中操作。比如:

  1. procedure Tfrm_dingdan.strgridGetFloatFormat(Sender: TObject; ACol, 
  2.   ARow: Integer; var IsFloat: Boolean; var FloatFormat: String); 
  3. begin 
  4.   case ACol of 
  5.     4: floatformat:='%.0f';     //第4列保留0位小数 
  6.     5: floatformat:='%.3f';     //第5列保留3位小数 
  7.     6: floatformat:='%.6f';    //第6列保留6位小数 
  8.     7: floatformat:='%.5f';    //第7列保留5位小数 
  9.   end; 
  10. end;

十五、Options—goRangeSelect:控制是否可以选择多行,goRowSelect控制选中整行

、AdvStringGrid做多表头
在onIsFixedCell事件中返回true的就是表头

--------------------------------------------------------------------
2、怎样实现AdvStringGrid的列宽自动按内容调整?
   怎样实现AdvStringGrid的列宽自动按列标题宽度调整?
   autosize属性的作用是什么?
  
autosize,可以根据内容调整列宽。
自动按标题列调整,自己在其RESIZE事件里对COLWIDTHS[I]赋值就行了。

procedure AutoSizeColumns(const DoFixedCols: Boolean; const Padding: Integer);
例:AdvStringGrid1.AutoSizeColumns(False,16);
 
AdvStringGrid1.AutoSizeColumns(False,16);
第一参数:是否为固定列;第二个参数,文字后面留的空格数
 
所有单元格自动调整,由第一个参数设置是否含固定单元,
如要固定行折行显示应将其行高设为自动调整即:
AdvStringGrid1.AutoSizeRow(0);
--------------------------------------------------------------------- 
3、AdvStringGrid插入checkbox列
 把advstringgrid的option属性中的goEditing 设为true
 
 在from create事件中加入
 

  1.  for i:=1 to advstringgrid.rowcount-1 do
  2.     advstringgrid.AddCheckBox(1,i,false,false);   //其中1表示所在列数
  3.    GetCheckBoxState(col,row) 可以查询的
  4.    Bchek:Boolean;
  5.    AdvSGrid.GetCheckBoxState(Col,Arow,Bchek);

---------------------------------------------------------------------
4、stringGrid中的行或列和并
 

  1.   grdList.MergeCells(0,0,2,2);
  2.    grdList.Cells[0,0]:='123456';
  3.    advstringgrid.mergecol(3,4);
  4.    advstringgrid..MergeCells(0,0,2,2);

5、  
with advStringGrid1 do   //引用单元格时, 列数在前,行数在后.
MergeCells(0,0,1,3);   
//合并单元格.前两参数为列数行数. 后两参数分别为要合并的列数和行数
Cells[1,0] := Format('分度线( %s )',[m_sMeasureRangeUnit]);;

          MergeCells(3,JieDianStart - 1,1,1);
          Cells[3,JieDianStart - 1] := '动作方式';
          ColWidths[3] := ColWidths[3] + 10;
          Colors[3,JieDianStart - 1] := FixedColor;
          FontNames[3,JieDianStart - 1] := FixedFont.Name;
          FontSizes[3,JieDianStart - 1] := FixedFont.Size;
          FontStyles[3,JieDianStart - 1] := FixedFont.Style;


前面是我在程序中拉的一段.
控件常用事件:
//单元格可否被修改
onCanEditCell(Sender: TObject; ARow,  ACol: Integer; var CanEdit: Boolean);
begin
  if ACol = 0 then
    CanEdit := false;  //false不能修改
end;

//对齐方式
onGetAlignment(Sender: TObject; ARow,
  ACol: Integer; var HAlign: TAlignment; var VAlign: TVAlignment);
begin
     HAlign := taCenter;
     VAlign := vtaCenter;
end;
//是否固定列 ,即标题列, 在表中非开头行需要固定标题列时很有用
onIsFixedCell(Sender: TObject; ARow,
  ACol: Integer; var IsFixed: Boolean);
begin
     if(ARow = 10) then
     begin
          IsFixed := True;
     end;
end;
-------------------------------------------------------------------------------
6、如何在AdvStringGrid中为每个单元格内的字体定制颜色
在OnDrawCell事件(看名字这个控件应该有这个事件把,呵呵!)写如下代码:
(Sender as TAdvStringGrid).Canvas.Font.Color:=clNavy;
7、cell中内嵌combobox
OnGetEditorType事件
  if ACol = 1 then
  begin
        aEditor := edComboList;
        grdMain.ClearComboString;
        grdMain.AddComboString('借');
        grdMain.AddComboString('  贷');
  end;

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Explain the InnoDB Buffer Pool and its importance for performance.Explain the InnoDB Buffer Pool and its importance for performance.Apr 19, 2025 am 12:24 AM

InnoDBBufferPool reduces disk I/O by caching data and indexing pages, improving database performance. Its working principle includes: 1. Data reading: Read data from BufferPool; 2. Data writing: After modifying the data, write to BufferPool and refresh it to disk regularly; 3. Cache management: Use the LRU algorithm to manage cache pages; 4. Reading mechanism: Load adjacent data pages in advance. By sizing the BufferPool and using multiple instances, database performance can be optimized.

MySQL vs. Other Programming Languages: A ComparisonMySQL vs. Other Programming Languages: A ComparisonApr 19, 2025 am 12:22 AM

Compared with other programming languages, MySQL is mainly used to store and manage data, while other languages ​​such as Python, Java, and C are used for logical processing and application development. MySQL is known for its high performance, scalability and cross-platform support, suitable for data management needs, while other languages ​​have advantages in their respective fields such as data analytics, enterprise applications, and system programming.

Learning MySQL: A Step-by-Step Guide for New UsersLearning MySQL: A Step-by-Step Guide for New UsersApr 19, 2025 am 12:19 AM

MySQL is worth learning because it is a powerful open source database management system suitable for data storage, management and analysis. 1) MySQL is a relational database that uses SQL to operate data and is suitable for structured data management. 2) The SQL language is the key to interacting with MySQL and supports CRUD operations. 3) The working principle of MySQL includes client/server architecture, storage engine and query optimizer. 4) Basic usage includes creating databases and tables, and advanced usage involves joining tables using JOIN. 5) Common errors include syntax errors and permission issues, and debugging skills include checking syntax and using EXPLAIN commands. 6) Performance optimization involves the use of indexes, optimization of SQL statements and regular maintenance of databases.

MySQL: Essential Skills for Beginners to MasterMySQL: Essential Skills for Beginners to MasterApr 18, 2025 am 12:24 AM

MySQL is suitable for beginners to learn database skills. 1. Install MySQL server and client tools. 2. Understand basic SQL queries, such as SELECT. 3. Master data operations: create tables, insert, update, and delete data. 4. Learn advanced skills: subquery and window functions. 5. Debugging and optimization: Check syntax, use indexes, avoid SELECT*, and use LIMIT.

MySQL: Structured Data and Relational DatabasesMySQL: Structured Data and Relational DatabasesApr 18, 2025 am 12:22 AM

MySQL efficiently manages structured data through table structure and SQL query, and implements inter-table relationships through foreign keys. 1. Define the data format and type when creating a table. 2. Use foreign keys to establish relationships between tables. 3. Improve performance through indexing and query optimization. 4. Regularly backup and monitor databases to ensure data security and performance optimization.

MySQL: Key Features and Capabilities ExplainedMySQL: Key Features and Capabilities ExplainedApr 18, 2025 am 12:17 AM

MySQL is an open source relational database management system that is widely used in Web development. Its key features include: 1. Supports multiple storage engines, such as InnoDB and MyISAM, suitable for different scenarios; 2. Provides master-slave replication functions to facilitate load balancing and data backup; 3. Improve query efficiency through query optimization and index use.

The Purpose of SQL: Interacting with MySQL DatabasesThe Purpose of SQL: Interacting with MySQL DatabasesApr 18, 2025 am 12:12 AM

SQL is used to interact with MySQL database to realize data addition, deletion, modification, inspection and database design. 1) SQL performs data operations through SELECT, INSERT, UPDATE, DELETE statements; 2) Use CREATE, ALTER, DROP statements for database design and management; 3) Complex queries and data analysis are implemented through SQL to improve business decision-making efficiency.

MySQL for Beginners: Getting Started with Database ManagementMySQL for Beginners: Getting Started with Database ManagementApr 18, 2025 am 12:10 AM

The basic operations of MySQL include creating databases, tables, and using SQL to perform CRUD operations on data. 1. Create a database: CREATEDATABASEmy_first_db; 2. Create a table: CREATETABLEbooks(idINTAUTO_INCREMENTPRIMARYKEY, titleVARCHAR(100)NOTNULL, authorVARCHAR(100)NOTNULL, published_yearINT); 3. Insert data: INSERTINTObooks(title, author, published_year)VA

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

MantisBT

MantisBT

Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

VSCode Windows 64-bit Download

VSCode Windows 64-bit Download

A free and powerful IDE editor launched by Microsoft

SublimeText3 Linux new version

SublimeText3 Linux new version

SublimeText3 Linux latest version

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools