问题:
在dbgrid有两个字段是连在table上的.还有一个字段是我用加上的column.
(就是数据表中只有两个字段.dbgrid中有三个columns.),如果我要在dbgrid中输入数据.dbgrid是连在表上.但是第三个column没有办法输入.以前我有看过有人就有用过这种办法.但是我没有办法做到,想请高手帮忙写这段代码.
在dbgrid有两个字段是连在table上的.还有一个字段是我用加上的column.
(就是数据表中只有两个字段.dbgrid中有三个columns.),如果我要在dbgrid中输入数据.dbgrid是连在表上.但是第三个column没有办法输入.以前我有看过有人就有用过这种办法.但是我没有办法做到,想请高手帮忙写这段代码.
解决方案 »
- class TDBComponentMath not found!哪位知道是什么控件啊,给个详细下载地址吧
- 界面编辑器Extlib 2.0 与TiPipe控件结合编程的问题
- 请问哪位有CMPP3.0协议?或者提供一下下载链接?
- 请教:如何判断EDIT框中输入的是数字
- RxLib for D7的下载地址 www.oxygensoftware.co.uk/download/rx275d7.zip
- 怎么判断一个文件是否已被打开
- <微型小说选刊>第6期上登的一个广告称,78元能买到cd随声听,还有100多元的笔记本电脑.各位有没有买到的.或者这完全是个骗局.可"微型小说选
- 改变窗口大小时窗口会抖动,我用lockwindowupdate(handle)/lockwindowupdate(0)后, 改变窗口大小时桌面会抖动,怎幺办呢
- Socket编程的奇怪错误,请大家一定帮忙,我找不到问题在哪里
- 急急急!!!!!!!!!!!!!!!!
- ado执行sql语句,关于msado15.dll的错失怎么引起的?
- 我的数据库操作为何只能执行一个,在执行另一个就报错?见内容
如果dbgrid的column没有和子段关联,是不能直接输入的
但是可以用我的方法来显示 :)
Left = 192
Top = 107
Width = 696
Height = 480
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 DBGrid1: TDBGrid
Left = 160
Top = 80
Width = 417
Height = 249
DataSource = DataSource1
TabOrder = 0
TitleFont.Charset = DEFAULT_CHARSET
TitleFont.Color = clWindowText
TitleFont.Height = -11
TitleFont.Name = 'MS Sans Serif'
TitleFont.Style = []
OnDrawColumnCell = DBGrid1DrawColumnCell
Columns = <
item
Expanded = False
FieldName = 'age'
Visible = True
end
item
Expanded = False
FieldName = 'card'
Visible = True
end
item
Expanded = False
FieldName = 'name'
Visible = True
end
item
Expanded = False
FieldName = 'sex'
Visible = True
end
item
Expanded = False
FieldName = 'name'
Title.Caption = 'phone'
Visible = True
end>
end
object DataSource1: TDataSource
DataSet = ADOTable1
Left = 64
Top = 40
end
object ADOTable1: TADOTable
Active = True
Connection = ADOConnection1
CursorType = ctStatic
TableName = '表2'
Left = 120
Top = 48
end
object ADOConnection1: TADOConnection
Connected = True
ConnectionString =
'Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security In' +
'fo=False;Initial Catalog=gg;Data Source=YZ89'
LoginPrompt = False
Provider = 'SQLOLEDB.1'
Left = 48
Top = 112
end
object ADOTable2: TADOTable
Active = True
Connection = ADOConnection1
CursorType = ctStatic
TableName = '表1'
Left = 80
Top = 328
end
end
procedure TForm1.DBGrid1DrawColumnCell(Sender: TObject; const Rect: TRect;
DataCol: Integer; Column: TColumn; State: TGridDrawState);
var str:string;
begin
if Column.Title.Caption = 'phone' then
begin
ADOTable2.Locate('name',Column.Field.Value,[loCaseInsensitive]);
str:=ADOTable2['phone'];
(Sender As TDBGrid).Canvas.TextRect(Rect, Rect.Left + 20, Rect.Top + 2, str);
end;
end;