最近看一个类似于GBGrid的例子,每次向这个Grid中添加新条目的时候,新添加的行始终在Grid的最上边,前边添加的都向下滚动。
比如新添的是A这一行,下一条新添的B这一行,B就在A的上边,A就变成第二行。依此类推。不知道我表述清楚了没这是个什么控件?或者是常用的DBGrid,StringGrid等等的设置不对?困惑ing
比如新添的是A这一行,下一条新添的B这一行,B就在A的上边,A就变成第二行。依此类推。不知道我表述清楚了没这是个什么控件?或者是常用的DBGrid,StringGrid等等的设置不对?困惑ing
解决方案 »
- 关于在另一个窗体中显示query查询的数据
- 多线程调用时报"abstract error"!
- 请给我个思路(关于自解压程序)
- 查询统计
- 请教高手 idhttp.post 得到的网页内容(网页代码) 怎么显示网页(web页面)html ??
- 我要把表中的数据存成文本文件...
- 如何将prn文件打印到一台网络打印机上???
- 我下载的.rar文件,用winrar解压成.pdf文件后,再用Acrobat 4.0打不开!!
- 截获鼠标右键点击
- 向各位请教一个奇怪的问题,这个程序有啥问题?92大分送上!
- delphi 交流群4654765
- 我用panel.handle获取视频回放,第一次回放没有问题,第二次回放就有问题
try
dbgrd1.DataSource.DataSet.First;
dbgrd1.DataSource.DataSet.Insert;
finally
dbgrd1.DataSource.DataSet.EnableControls;
end;
For Paradox tables with primary indexes, the record is inserted into the dataset in a position based on its index. For Paradox tables without primary indexes, the record is inserted into the dataset at the current position. For dBASE, FoxPro, and Access tables, the record is physically appended to the dataset at the end. If an index happens to be active, the new record may appear in a position relative to the index, but the record is still actually stored at the end of the table. For SQL databases, the physical location of the insert is implementation-specific. For indexed tables, the index is updated with the new record information. After the new record is applied back to the database server, its physical location is database-specific. For indexed tables, the index is updated with the new record information.
追加就在最后一行追加;
所有DBGrid都符合这一规则。
包括TDBGrid, TDBGridEh, TcxGrid, TdxGrid等。
当然后两种有更特殊的方法,直接设置属性就可以在首行添加。
其他的可参考#3楼代码
然后在陆续采集、写入的过程中,采用 Value:= 采集函数返回值;(Single)
StringGrid1.RowCount:= Count+1;
StringGrid1.Cells[0,Count]:= FormatFloat('0.000',Value);
StringGrid1.Row:= Count;这样的话,添加的数据条目就是上边说的Append的结果,逐条添加在所有条目的后边;
而我想要的是上边说的Insert的结果,新的条目始终在最前边。这个是不需要保存数据库的,所以,DataSource,DataSet什么的都不需要。应该怎么做?越弄越迷糊了
第一、自己控制數據移動unit Unit1;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, Grids;type
TForm1 = class(TForm)
StringGrid1: TStringGrid;
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
procedure InsertRow(aRow: Integer);
procedure MoveRowUp(vGrid:TStringGrid; vrow:integer);
public
{ Public declarations }
end;var
Form1: TForm1;implementation{$R *.dfm}procedure TForm1.Button1Click(Sender: TObject);
begin
stringGrid1.RowCount := stringGrid1.RowCount +1;
MoveRowUp(stringgrid1,2);//插入到第二行
end;procedure TForm1.MoveRowUp(vgrid: TStringGrid; vrow:integer);
var
s: string;
i:integer;
begin
if vrow=1 then exit;
for i:=0 to vgrid.colcount-1 do
begin
s:=vgrid.cells[i,vrow-1];
vgrid.cells[i,vrow-1]:=vgrid.cells[i,vrow];
vgrid.cells[i,vrow]:=s;
end;
vgrid.row:= vrow;
vgrid.repaint;
end;
end.
第二種,修改控件,利用MoveRow(位于protected),如下:type
TStringGridEx = class(TStringGrid)
protected
procedure InsertRow(ARow: Longint);
end;implementationprocedure TStringGridEx.InsertRow(ARow: Longint);
var
GemRow: Integer;
begin
GemRow := Row;
while ARow < FixedRows do Inc(ARow);
RowCount := RowCount + 1;
MoveRow(RowCount - 1, ARow);
Row := GemRow;
Rows[Row].Clear;
end;end.
[12:13:15][正向]7.872V下一条采集到了以后,显示变成:
[12:13:16][正向]7.881V
[12:13:15][正向]7.872V再来一条,显示就是:
[12:13:18][正向]7.867V
[12:13:16][正向]7.881V
[12:13:15][正向]7.872V要能选中某一行,需要做个弹出右键菜单的。我自己觉得这个类似一个StringGrid或者DBGrid,楼上有大侠说是可以用Dev系列的,我也在想,应该就是一个可以在属性里边设置的控件吧
但是发现个问题就是最下边一行始终是空白的,不太好看procedure TForm1.InsertRow(vGrid:TStringGrid; Str:Array of String);
var
i,j: Integer;
begin
if vGrid.RowCount=1 then
begin
for i:=0 to 2 do
vGrid.Cells[i,0]:= Str[i];
end
else
begin
for j:=0 to vGrid.ColCount-1 do
for i:=vGrid.RowCount-1 downto 1 do
begin
vGrid.Cells[j,i]:= vGrid.Cells[j,i-1];
end;
for i:=0 to 2 do
vGrid.Cells[i,0]:= Str[i];
end;
vGrid.RowCount:= vGrid.RowCount+1;
end;
procedure TForm1.InsertRow(vGrid:TStringGrid; Str:Array of String);
var
i,j: Integer;
begin
if One=1 then
begin
for i:=0 to 2 do
vGrid.Cells[i,0]:= Str[i];
One:= 2;
end
else
begin
vGrid.RowCount:= vGrid.RowCount+1;
for j:=0 to vGrid.ColCount-1 do
for i:=vGrid.RowCount-1 downto 1 do
begin
vGrid.Cells[j,i]:= vGrid.Cells[j,i-1];
end;
for i:=0 to 2 do
vGrid.Cells[i,0]:= Str[i];
end;
vGrid.Row:= 0;
end;
谢谢大家了。