1.我有一个表如下(表名:message,用dataset连接数据库) name sex age
a man 18
b women 20
c man 18如何把他显示在stringgrid中去呢?
如果我只显示name=a的资料呢?(帮我写代码出来,好不好,我没有用过呢)2.如何调节列的宽度呢?(能不能根据数据库的字节大小来自动调节呢?)3.如果我有很多资料,那么Stringgrid的行数会不会自动增加的?请各位大哥帮帮忙了,谢谢了
a man 18
b women 20
c man 18如何把他显示在stringgrid中去呢?
如果我只显示name=a的资料呢?(帮我写代码出来,好不好,我没有用过呢)2.如何调节列的宽度呢?(能不能根据数据库的字节大小来自动调节呢?)3.如果我有很多资料,那么Stringgrid的行数会不会自动增加的?请各位大哥帮帮忙了,谢谢了
解决方案 »
- 取得StringGrid点击的当前单元格的列索引或者行索引
- 小弟用fastreport3.0打印报表时,如何控制每页固定的打印行数(比如12行)?
- 很生气.来发发牢骚.顺便放放分.
- 局域网内2台计算机或同台计算机不同进程间用什么方法传输数据最快,请高手指教!!
- 正在开发或准备开发报表控件的朋友,请到这里来一起切磋切磋,QQ群:6030791
- 如何调整bmp图形亮度,答得好的有50分
- 如何跟蹤.調試????
- 请问各位老大我的ADO的udl文件在win98怎么不能用啊提示文件不能用所以属性无效
- 我想把DBlistBox控件与ADOQuery1绑定,DBlistBox =: ADOQuery1,这样写对吗?
- 大家好,我是寂寞寒冰,来这里不分日夜的混了好几天了,以后希望大家能关照我一下!谢谢
- 请问在设计期时选中一个控件就会出现选中的标记,请问这个效果怎么实现,在线等,回答有效立即给分!
- TStringList引用后,窗体关闭就异常,请教???
StringGrid要自己填进去的,你爱填哪列填哪列,你用的可能是DBGrid吧.
2
StringGrid1.RowHeights[0] := 20;
StringGrid1.ColWidths[0] := 100;
3
不会,要你自己控制行数,DBGrid会.
StringGrid1.RowCount := 1000;
begin
ColCount :=4;
RowCount :=2;
FixedCols :=3;
ColWidths[0] :=0;
ColWidths[1] :=1;
ColWidths[2] :=180;
ColWidths[3] :=400;
Cells[0,0] :='name';
Cells[1,0] :='sex;
Cells[2,0] :='age;
end; While Not Query.Eof do
Begin
StringGrid1.Cells[0,StringGrid1.RowCount-1] :=trim(Query.FieldByName('FIELD_TYPE').AsString);
StringGrid1.Cells[1,StringGrid1.RowCount-1] :=trim(Query.FieldByName('FIELD_TYPE').AsString);
.....
Query.Next;
end;
var
i,j: integer
with adodataset do
begin
close;
CommonText:= 'select * from message where name = ''a''';
active := True;
stringgrid1.Clear;
First;
i := 1;
while not Eof do
begin
for j := 0 to FieldCount - 1 do
begin
stringgrid1.Rows[i].Add(Fields.Fields[j].AsString);
end;
i := i + 1;
Next;
end;
//显示标题
for i := 0 to FieldCount - 1 do
begin
stringgrid1.Rows[0].Add(Fields.Fields[i].FieldName);
end; stringgrid1.AutoSize := True;//自动列宽
end;
方法是在对StringGrid填充完文本串后调用SetOptimalGridCellWidth过程。 -----------程序片断------------------------------------------------- (* $Header$ Module Name : General\BSGrids.pas Main Program : Several. Description : StringGrid support functions. 03/21/2000 enhanced by William Sorensen *) unit BSGrids; interface uses Grids; type TExcludeColumns = set of 0..255; procedure SetOptimalGridCellWidth(sg: TStringGrid; ExcludeColumns: TExcludeColumns); // Sets column widths of a StringGrid to avoid truncation of text. // Fill grid with desired text strings first. // If a column contains no text, DefaultColWidth will be used. // Pass [] for ExcludeColumns to process all columns, including Fixed. // Columns whose numbers (0-based) are specified in ExcludeColumns will not // have their widths adjusted. implementation uses Math; // we need the Max function procedure SetOptimalGridCellWidth(sg: TStringGrid; ExcludeColumns: TExcludeColumns); var i : Integer; j : Integer; max_width : Integer; begin with sg do begin // If the grid's Paint method hasn't been called yet, // the grid's canvas won't use the right font for TextWidth. // (TCustomGrid.Paint normally sets this, under DrawCells.) Canvas.Font.Assign(Font); for i := 0 to (ColCount - 1) do begin if i in ExcludeColumns then Continue; max_width := 0; // Search for the maximal Text width of the current column. for j := 0 to (RowCount - 1) do max_width := Math.Max(max_width,Canvas.TextWidth(Cells[i,j])); // The hardcode of 4 is based on twice the offset from the left // margin in TStringGrid.DrawCell. GridLineWidth is not relevant. if max_width > 0 then ColWidths[i] := max_width + 4 else ColWidths[i] := DefaultColWidth; end; { for } end; end; end.
就是我用了一个DataTimepicker,比如读出得数据都是2004-10-28,我怎么可以得到200410这种形式得日期呢?感激不尽
比如有这样一个表:name sex age height study
a man 18 20 good
b women 20 18 bad
c man 18 19 cool
a man 21 22 very我这样写一个sql语句:
select name,sex,sum(age) as age,sum(height) as height from message where name='a'但需要作出这样一个判断,当sum(age) >sum(height) ,将sum(age) -sum(height) ,得到得差额插入到name='a'的那一行,age的那一列,而置height=0。如果sum(age) <sum(height) ,则将差额插入到name='a'的那一行,height的那一列,而置age=0.即是:
——————————————————————————————————————
name sex age height
-------------------------------------------
a man 0 3
-----------------------------------------------------------------------求求各位了,这个stringgrid对我来说太难了,:)