Typesetting math: 100%

收集的stringgrid的技巧

 stringgrid

StringGrid行列的增加和删除
如何编写使StringGrid中的一列具有Check功能,和CheckBox效果一样
StringGrid组件Cells内容分行显示在Tstringgrid.ondrawcell事件中
在StringGrid怎样制作只读的列在 OnSelectCell事件处理程序中
stringgrid从文本读入的问题
StringGrid组件Cells内容对齐
StringGird的行列背景色设置
怎么改变StringGrid控件某一列的背景和某一列的只读属性
StringGrid控件标题栏的对齐
怎么改变StringGrid控件某一列的背景和某一列的只读属性
StringGrid控件标题栏的对齐
在stringGrid中使用回车键模拟TAB键切换单元格的功能实现
stringgrid如何清空
让记录在StringGrid中分页显示在
打印StringGrid
如何实现在stringgrid中删除鼠标点中的那一行,下一行再顶上的效果
让stringgrid点列头进行排序
正确地设置StringGrid列宽而不截断任何一个文字方法
实现StringGrid的删除,插入,排序行操作
TstringGrid 的行列合并研究



StringGrid行列的增加和删除
type
 TExCell = class(TStringGrid)

public
 procedure DeleteRow(ARow: Longint);
 procedure DeleteColumn(ACol: Longint);
 procedure InsertRow(ARow: LongInt);
 procedure InsertColumn(ACol: LongInt);
end;

procedure TExCell.InsertColumn(ACol: Integer);
begin
 ColCount :=ColCount +1;
 MoveColumn(ColCount-1, ACol);
end;

procedure TExCell.InsertRow(ARow: Integer);
begin
 RowCount :=RowCount +1;
 MoveRow(RowCount-1, ARow);
end;

procedure TExCell.DeleteColumn(ACol: Longint);
begin
 MoveColumn(ACol, ColCount -1);
 ColCount := ColCount - 1;
end;

procedure TExCell.DeleteRow(ARow: Longint);
begin
 MoveRow(ARow, RowCount - 1);
 RowCount := RowCount - 1;
end;





  如何编写使StringGrid中的一列具有Check功能,和CheckBox效果一样
 unit Unit1;

interface

uses
 Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, Grids;

type
 TForm1 = class(TForm)
 grid: TStringGrid;
 procedure FormCreate(Sender: TObject);
 procedure gridDrawCell(Sender: TObject; ACol, ARow: Integer;
 Rect: TRect; State: TGridDrawState);
 procedure gridClick(Sender: TObject);

 private
{ Private declarations }

 public
{ Public declarations }

end;

var
 Form1: TForm1;
 fcheck,fnocheck:tbitmap;

implementation

{[Math Processing Error]HeaderModuleName:General\BSGrids.pasMainProgram:Several.Description:StringGridsupportfunctions.03/21/2000enhancedbyWilliamSorensen)unitBSGrids;interfaceusesGrids;typeTExcludeColumns=setof0..255;procedureSetOptimalGridCellWidth(sg:TStringGrid;ExcludeColumns:TExcludeColumns);//SetscolumnwidthsofaStringGridtoavoidtruncationoftext.//Fillgridwithdesiredtextstringsfirst.//Ifacolumncontainsnotext,DefaultColWidthwillbeused.//Pass[]forExcludeColumnstoprocessallcolumns,includingFixed.//Columnswhosenumbers(0based)arespecifiedinExcludeColumnswillnot//havetheirwidthsadjusted.implementationusesMath;//weneedtheMaxfunctionprocedureSetOptimalGridCellWidth(sg:TStringGrid;ExcludeColumns:TExcludeColumns);vari:Integer;j:Integer;maxwidth:Integer;beginwithsgdobegin//IfthegridsPaintmethodhasntbeencalledyet,//thegridscanvaswontusetherightfontforTextWidth.//(TCustomGrid.Paintnormallysetsthis,underDrawCells.)Canvas.Font.Assign(Font);fori:=0to(ColCount1)dobeginifiinExcludeColumnsthenContinue;maxwidth:=0;//SearchforthemaximalTextwidthofthecurrentcolumn.forj:=0to(RowCount1)domaxwidth:=Math.Max(maxwidth,Canvas.TextWidth(Cells[i,j]));//Thehardcodeof4isbasedontwicetheoffsetfromtheleft//margininTStringGrid.DrawCell.GridLineWidthisnotrelevant.ifmaxwidth>0thenColWidths[i]:=maxwidth+4elseColWidths[i]:=DefaultColWidth;end;forend;end;end.200311199:22:09StringGrid//ProcedureGridRemoveColumn(StrGrid:TStringGrid;DelColumn:Integer);VarColumn:Integer;beginIfDelColumn<=StrGrid.ColCountthenBeginForColumn:=DelColumnToStrGrid.ColCount1doStrGrid.Cols[Column1].Assign(StrGrid.Cols[Column]);StrGrid.ColCount:=StrGrid.ColCount1;End;end;//ProcedureGridAddColumn(StrGrid:TStringGrid;NewColumn:Integer);VarColumn:Integer;beginStrGrid.ColCount:=StrGrid.ColCount+1;ForColumn:=StrGrid.ColCount1downtoNewColumndoStrGrid.Cols[Column].Assign(StrGrid.Cols[Column1]);StrGrid.Cols[NewColumn1].Text:=;end;//ProcedureGridSort(StrGrid:TStringGrid;NoColumn:Integer);VarLine,PosActual:Integer;Row:TStrings;beginRenglon:=TStringList.Create;ForLine:=1toStrGrid.RowCount1doBeginPosActual:=Line;Row.Assign(TStringlist(StrGrid.Rows[PosActual]));WhileTruedoBeginIf(PosActual=0)or(StrToInt(Row.Strings[NoColumn1])>=StrToInt(StrGrid.Cells[NoColumn1,PosActual1]))thenBreak;StrGrid.Rows[PosActual]:=StrGrid.Rows[PosActual1];Dec(PosActual);End;IfStrToInt(Row.Strings[NoColumn1])<StrToInt(StrGrid.Cells[NoColumn1,PosActual])thenStrGrid.Rows[PosActual]:=Row;End;Renglon.Free;end;2003112011:28:56TstringGridunitUnit1;////STringGrid//interfaceusesWindows,Messages,SysUtils,Classes,Graphics,Controls,Forms,Dialogs,StdCtrls,Db,ADODB,DBTables,Grids;//typeTForm1=class(TForm)procedureFormCreate(Sender:TObject);procedureSGDrawCell(Sender:TObject;ACol,ARow:Integer;Rect:TRect;State:TGridDrawState);procedureSGTopLeftChanged(Sender:TObject);privatePrivatedeclarationspublicPublicdeclarationsend;varForm1:TForm1;implementation$R.DFM//StringGrid//varsg:TStringGrid;procedureTForm1.FormCreate(Sender:TObject);vari,j:integer;beginSg:=TStringGrid.Create(self);withSGdobeginparent:=self;align:=alclient;DefaultDrawing:=false;FixedColor:=clYellow;RowCount:=30;ColCount:=20;FixedCols:=1;FixedRows:=1;GridLineWidth:=0;Options:=Options+[goEditing][goVertLine,goHorzLine,goRangeSelect];OnDrawCell:=SGDrawCell;OnTopLeftChanged:=SGTopLeftChanged;Canvas.Font.name:=;Canvas.Font.Size:=10;fori:=0tocolCount1doforj:=0toRowCount1docells[i,j]:=Format(ff0000;

Fixed:=false;
if (Arow<d.FixedRows) or (ACol<d.Fixedcols) then
begin
 d.Canvas.brush.color:=d.FixedColor;
 d.Canvas.Font.color:=ff00ff;Fixed:=True;//d.Canvas.Font.style:=d.Canvas.Font.style+[fsBold];end;ifgdfocusedinstatethenbegind.canvas.Brush.color:=00ff00;
end;
if fixed then
begin
 d.Canvas.Pen.color:=0;d.canvas.Rectangle(r);d.Canvas.Pen.color:=f0f0f0;
 d.Canvas.Pen.Width:=2;
 d.canvas.Moveto(r.left+1,r.top+2);
 d.canvas.Lineto(r.left+r.right,r.top+2);

 d.Canvas.Pen.color:=808080;d.Canvas.Pen.Width:=1;d.canvas.Moveto(r.Left+1,r.bottom1);d.canvas.Lineto(r.left+r.right,r.bottom1);endelsebegind.Canvas.Pen.color:=0;
 d.Canvas.Pen.Width:=1;
 d.canvas.Rectangle(r);
end;
n:=r.top+4;
ts:=TStringList.Create;
ts.CommaText:=s;
for i:=0 to ts.Count-1 do
begin
 d.canvas.Textout(r.left+4,n,ts[i]);
 inc(n,d.RowHeights[ARow]);
end;
end;

//重载 OnTopLeftChange事件,特别是行的合并
procedure TForm1.SGTopLeftChanged(Sender: TObject);
var
d:TStringGrid;
begin
d:=TStringGrid(Sender);
d.Cells[0,1]:=d.Cells[0,1];
d.Cells[0,2]:=d.Cells[0,2];
end;

end.

posted @   数据酷软件  阅读(1712)  评论(0编辑  收藏  举报
编辑推荐:
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
阅读排行:
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· 阿里巴巴 QwQ-32B真的超越了 DeepSeek R-1吗?
· 【译】Visual Studio 中新的强大生产力特性
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 【设计模式】告别冗长if-else语句:使用策略模式优化代码结构
点击右上角即可分享
微信分享提示