请教:
我的窗体上有个 dbgrideh 控件
并且新建了3 个列现在我单击 button1 按纽,
使 dbgrigeh 自己增加一行这一行的
第一列是 含有 '....'(浏览文件用的,相当于 opendialog)
第二列是 含有 下拉列表框
第三列是 含有 复选框(相当于 checkbox)procedure TForm1.Button1Click(Sender: TObject);
beginend;这样的程序要怎么写啊?谢谢!
我的窗体上有个 dbgrideh 控件
并且新建了3 个列现在我单击 button1 按纽,
使 dbgrigeh 自己增加一行这一行的
第一列是 含有 '....'(浏览文件用的,相当于 opendialog)
第二列是 含有 下拉列表框
第三列是 含有 复选框(相当于 checkbox)procedure TForm1.Button1Click(Sender: TObject);
beginend;这样的程序要怎么写啊?谢谢!
exit;
try
dm.ADOQuery1.Close;
dm.ADOQuery1.SQL.Clear;
dm.ADOQuery1.SQL.Add('select * from yh_table ');
dm.ADOQuery1.Open;
dm.ADOQuery1.Append;
dm.ADOQuery1.FieldByName('字段一').AsString:=edit1.Text;
dm.ADOQuery1.FieldByName('字段二').AsString:=edit2.Text;
dm.ADOQuery1.FieldByName('字段三').AsString:=edit3.Text;
dm.ADOQuery1.Post;
showmessage('数据保存成功'); dm.ADOQuery3.Close;
dm.ADOQuery3.SQL.Clear;
dm.ADOQuery3.SQL.Add('select * from yh_table');
dm.ADOQuery3.Open;
ADOQUERY要和DBgrid绑定,才能实现
也就是说没有 datasource,dataset 的
我需要是按一下 button 按钮,就在 dbgrideh 上添加一行啊`谢谢!
为什么必须要在dbgrideh里面显示呢?
有点难度
不一定要在 dbgrideh 里实现啊可以在哪个控件实现?谢谢!
TAdvStringGrid是 delphi7 自己带的,还是第三方控件啊哪个好一些?谢谢!
TAdvStringGrid都是第三方控件,Delphi盒子上面有
大哥,可以用 QQ 发给我不啊
QQ:19335776
谢谢!
您好!是这样的:
我没有下到单独的 TAdvStringGrid
下了 TMS ,可是我下了几个都不能安装TStringGrid
没有找到大哥,您可以把
TStringGrid
TAdvStringGrid传给我吗?我比较急非常感谢!
下拉列表框
复选框(相当于 checkbox)
updown 这些都有是吗/谢谢!
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, AdvGrid, Grids, BaseGrid, Buttons;type
TForm1 = class(TForm)
AdvStringGrid1: TAdvStringGrid;
ComboBox1: TComboBox;
OpenDialog1: TOpenDialog;
CheckBox1: TCheckBox;
SpeedButton1: TSpeedButton;
procedure AdvStringGrid1ButtonClick(Sender: TObject; ACol,
ARow: Integer);
procedure CheckBox1Click(Sender: TObject);
procedure AdvStringGrid1CheckBoxClick(Sender: TObject; ACol,
ARow: Integer; State: Boolean);
procedure AdvStringGrid1DrawCell(Sender: TObject; ACol, ARow: Integer;
Rect: TRect; State: TGridDrawState);
procedure ComboBox1Change(Sender: TObject);
procedure SpeedButton1Click(Sender: TObject); private
{ Private declarations }
public
{ Public declarations }
end;var
Form1: TForm1;implementation{$R *.dfm}
procedure TForm1.AdvStringGrid1ButtonClick(Sender: TObject; ACol,
ARow: Integer);
begin
if ACol=0 then
begin
if OpenDialog1.Execute then
AdvStringGrid1.Cells[3,ARow]:=OpenDialog1.FileName;
end;
end;procedure TForm1.CheckBox1Click(Sender: TObject);
begin
AdvStringGrid1.SetCheckBoxState(2,AdvStringGrid1.Row,CheckBox1.Checked);
end;procedure TForm1.AdvStringGrid1CheckBoxClick(Sender: TObject; ACol,
ARow: Integer; State: Boolean);
begin
CheckBox1.OnClick:=nil;
CheckBox1.Checked:=State;
CheckBox1.OnClick:=CheckBox1Click ;
end;procedure TForm1.AdvStringGrid1DrawCell(Sender: TObject; ACol,
ARow: Integer; Rect: TRect; State: TGridDrawState);
begin
if (gdFocused in state) then
begin
if ACol=1 then
begin
with ComboBox1 do
begin
if (Left<>rect.left+AdvStringGrid1.left)or
(top<>rect.top+AdvStringGrid1.top)or(not Visible)then
begin
Left:=rect.left+AdvStringGrid1.left;
top:=rect.top+AdvStringGrid1.top;
width:=rect.right-rect.left+2;
height:=rect.bottom-rect.top;
visible:=true;
SetFocus;
ItemIndex:=Items.IndexOf(AdvStringGrid1.CurrentCell);
end;
end;
end
else ComboBox1.Visible:=False;
end;
end;procedure TForm1.ComboBox1Change(Sender: TObject);
begin
if ComboBox1.Visible then
AdvStringGrid1.cells[AdvStringGrid1.col,AdvStringGrid1.row]:=
ComboBox1.Items[ComboBox1.ItemIndex];
end;procedure TForm1.SpeedButton1Click(Sender: TObject);
var
r:Integer;
begin
if AdvStringGrid1.HasButton(0,1) then
AdvStringGrid1.AddRow;
r:=AdvStringGrid1.RowCount-1;
//加一个按钮
AdvStringGrid1.AddButton(0,r,AdvStringGrid1.ColWidths[0],AdvStringGrid1.RowHeights[r],'...',haFull,vaFull);
//加一个Checkbox
AdvStringGrid1.Cells[2,r]:=Format('第%d行',[r]);
AdvStringGrid1.AddCheckBox(2,r,False,False);
//Combobox隐藏,见OndrawCell事件
AdvStringGrid1.Row:=r;
AdvStringGrid1.Col:=1;
AdvStringGrid1.Update;
AdvStringGrid1.SetFocus;
end;end.
Left = 222
Top = 140
Width = 699
Height = 564
Caption = 'Form1'
Color = clBtnFace
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'MS Sans Serif'
Font.Style = []
OldCreateOrder = False
PixelsPerInch = 96
TextHeight = 13
object SpeedButton1: TSpeedButton
Left = 2
Top = 327
Width = 76
Height = 24
Caption = '加一行'
OnClick = SpeedButton1Click
end
object AdvStringGrid1: TAdvStringGrid
Left = 0
Top = 0
Width = 691
Height = 319
Cursor = crDefault
Align = alTop
ColCount = 4
DefaultRowHeight = 21
FixedCols = 0
RowCount = 2
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'Tahoma'
Font.Style = []
Options = [goFixedVertLine, goFixedHorzLine, goVertLine, goHorzLine, goRangeSelect, goDrawFocusSelected, goEditing]
ParentFont = False
ScrollBars = ssBoth
TabOrder = 0
OnDrawCell = AdvStringGrid1DrawCell
ActiveCellFont.Charset = DEFAULT_CHARSET
ActiveCellFont.Color = clWindowText
ActiveCellFont.Height = -11
ActiveCellFont.Name = 'Tahoma'
ActiveCellFont.Style = [fsBold]
OnButtonClick = AdvStringGrid1ButtonClick
OnCheckBoxClick = AdvStringGrid1CheckBoxClick
SearchFooter.FindNextCaption = 'Find next'
SearchFooter.FindPrevCaption = 'Find previous'
SearchFooter.HighLightCaption = 'Highlight'
SearchFooter.HintClose = 'Close'
SearchFooter.HintFindNext = 'Find next occurence'
SearchFooter.HintFindPrev = 'Find previous occurence'
SearchFooter.HintHighlight = 'Highlight occurences'
SearchFooter.MatchCaseCaption = 'Match case'
PrintSettings.DateFormat = 'dd/mm/yyyy'
PrintSettings.Font.Charset = DEFAULT_CHARSET
PrintSettings.Font.Color = clWindowText
PrintSettings.Font.Height = -11
PrintSettings.Font.Name = 'MS Sans Serif'
PrintSettings.Font.Style = []
PrintSettings.FixedFont.Charset = DEFAULT_CHARSET
PrintSettings.FixedFont.Color = clWindowText
PrintSettings.FixedFont.Height = -11
PrintSettings.FixedFont.Name = 'MS Sans Serif'
PrintSettings.FixedFont.Style = []
PrintSettings.HeaderFont.Charset = DEFAULT_CHARSET
PrintSettings.HeaderFont.Color = clWindowText
PrintSettings.HeaderFont.Height = -11
PrintSettings.HeaderFont.Name = 'MS Sans Serif'
PrintSettings.HeaderFont.Style = []
PrintSettings.FooterFont.Charset = DEFAULT_CHARSET
PrintSettings.FooterFont.Color = clWindowText
PrintSettings.FooterFont.Height = -11
PrintSettings.FooterFont.Name = 'MS Sans Serif'
PrintSettings.FooterFont.Style = []
PrintSettings.PageNumSep = '/'
FixedColWidth = 72
FixedFont.Charset = DEFAULT_CHARSET
FixedFont.Color = clWindowText
FixedFont.Height = -11
FixedFont.Name = 'Tahoma'
FixedFont.Style = [fsBold]
FloatFormat = '%.2f'
ColumnHeaders.Strings = (
'按钮'
'Combobox'
'Checkbox'
'FileName')
Filter = <>
Version = '3.3.0.1'
ColWidths = (
72
114
69
395)
end
object ComboBox1: TComboBox
Left = 50
Top = 156
Width = 145
Height = 21
Style = csDropDownList
ItemHeight = 13
TabOrder = 1
Visible = False
OnChange = ComboBox1Change
Items.Strings = (
'A'
'B'
'C'
'D')
end
object CheckBox1: TCheckBox
Left = 85
Top = 327
Width = 97
Height = 17
Caption = '测试CheckBox'
TabOrder = 2
OnClick = CheckBox1Click
end
object OpenDialog1: TOpenDialog
Left = 220
Top = 320
end
end
第二段代码存为Unit1.dfm
然后将Unit1加入到你的工程中,编译看看,再看看代码就知道了.用AdvStringGrid实现的.
太感谢了,我下载了几个 AdvStringGrid ,都没有安装上
大哥可以留下 QQ ,聊聊,好吗?
老板催我两西了!
QQ:19335776
http://www.2ccc.com/article.asp?articleid=3546