dbedit?? |
答題得分者是:andersonhsieh
|
cyl
中階會員 發表:163 回覆:171 積分:66 註冊:2002-07-11 發送簡訊給我 |
請問我有一個dbedit,我要從dbgrid中點選一筆資料,然後把這筆資料帶到dbedit
ex dbedit1.text:=table1.fieldsbyanme('a').asstring;
但是當我把游標focus回dbedit時,值又改回原值了,這是為什麼??
然到一定要這樣寫
table2.fieldsbyanme('a').asstring:=table1.fieldsbyanme('a').asstring;
但是此時的dbedit.text並沒有改變
還要再加上
dbedit1.text:=table1.fieldsbyanme('a').asstring;
而且每次在給值時還要
table2.edit;
所以我的程式碼為
table2.edit;
table2.fieldsbyanme('a').asstring:=table1.fieldsbyanme('a').asstring;
dbedit1.text:=table1.fieldsbyanme('a').asstring; 為什麼要這麼麻煩呢??
不是db原件嗎??
why??
ps:db是db3
| ||
andersonhsieh
版主 發表:33 回覆:531 積分:439 註冊:2002-06-10 發送簡訊給我 |
|||
cyl
中階會員 發表:163 回覆:171 積分:66 註冊:2002-07-11 發送簡訊給我 |
|||
andersonhsieh
版主 發表:33 回覆:531 積分:439 註冊:2002-06-10 發送簡訊給我 |
|||
cyl
中階會員 發表:163 回覆:171 積分:66 註冊:2002-07-11 發送簡訊給我 |
|||
andersonhsieh
版主 發表:33 回覆:531 積分:439 註冊:2002-06-10 發送簡訊給我 |
引言:將dbgrid.Option.dgCancelOnExit設為false試試 @@~~飛翔在天際的精靈~~@@引言: 一般來說資料感知元件除非連接的DATASET處在EDIT或INSERT的狀態下,指定其TEXT才會有效,否則都會回復成欄位中值的內容 @@~~飛翔在天際的精靈~~@@可是我在onCellClick中有寫table1.edit; 才把值帶過去,但是游標回到dbedit值就不見了, 還有為什麼如果dbgrid的某一個欄位有值,滑鼠click他,不會觸發???
------
@@~~飛翔在天際的精靈~~@@ |
||
cyl
中階會員 發表:163 回覆:171 積分:66 註冊:2002-07-11 發送簡訊給我 |
引言:可是我是要修改dbedit,把dbgrid.Option.dgCancelOnExit設為false似乎沒用 因為兩個來源並不一樣,值還是無法帶入引言:將dbgrid.Option.dgCancelOnExit設為false試試 @@~~飛翔在天際的精靈~~@@引言: 一般來說資料感知元件除非連接的DATASET處在EDIT或INSERT的狀態下,指定其TEXT才會有效,否則都會回復成欄位中值的內容 @@~~飛翔在天際的精靈~~@@可是我在onCellClick中有寫table1.edit; 才把值帶過去,但是游標回到dbedit值就不見了, 還有為什麼如果dbgrid的某一個欄位有值,滑鼠click他,不會觸發??? |
||
andersonhsieh
版主 發表:33 回覆:531 積分:439 註冊:2002-06-10 發送簡訊給我 |
|||
cyl
中階會員 發表:163 回覆:171 積分:66 註冊:2002-07-11 發送簡訊給我 |
|||
andersonhsieh
版主 發表:33 回覆:531 積分:439 註冊:2002-06-10 發送簡訊給我 |
|||
andersonhsieh
版主 發表:33 回覆:531 積分:439 註冊:2002-06-10 發送簡訊給我 |
我試過可以啊 unit Unit1; interface uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
Db, DBTables, StdCtrls, Mask, DBCtrls, Grids, DBGrids; type
TForm1 = class(TForm)
DBGrid1: TDBGrid;
DBEdit1: TDBEdit;
DataSource1: TDataSource;
DataSource2: TDataSource;
Table1: TTable;
Table2: TTable;
Table2NAME: TStringField;
Table2SIZE: TSmallintField;
Table2WEIGHT: TSmallintField;
Table2AREA: TStringField;
Table2BMP: TBlobField;
Table1Name: TStringField;
Table1Capital: TStringField;
Table1Continent: TStringField;
Table1Area: TFloatField;
Table1Population: TFloatField;
procedure DBGrid1CellClick(Column: TColumn);
private
{ Private declarations }
public
{ Public declarations }
end; var
Form1: TForm1; implementation {$R *.DFM} procedure TForm1.DBGrid1CellClick(Column: TColumn);
begin
Table2.Edit;
DBEdit1.Text := table1.fields[0].asstring;
end; end. object Form1: TForm1
Left = 191
Top = 132
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 = 246
Top = 36
Width = 320
Height = 120
DataSource = DataSource1
TabOrder = 0
TitleFont.Charset = DEFAULT_CHARSET
TitleFont.Color = clWindowText
TitleFont.Height = -11
TitleFont.Name = 'MS Sans Serif'
TitleFont.Style = []
OnCellClick = DBGrid1CellClick
Columns = <
item
Expanded = False
FieldName = 'Name'
Visible = True
end
item
Expanded = False
FieldName = 'Capital'
Visible = True
end
item
Expanded = False
FieldName = 'Continent'
Visible = True
end
item
Expanded = False
FieldName = 'Area'
Visible = True
end
item
Expanded = False
FieldName = 'Population'
Visible = True
end>
end
object DBEdit1: TDBEdit
Left = 30
Top = 52
Width = 121
Height = 21
DataField = 'AREA'
DataSource = DataSource2
TabOrder = 1
end
object DataSource1: TDataSource
DataSet = Table1
Left = 328
Top = 178
end
object DataSource2: TDataSource
DataSet = Table2
Left = 72
Top = 92
end
object Table1: TTable
Active = True
DatabaseName = 'DBDEMOS'
TableName = 'country.db'
Left = 346
Top = 274
object Table1Name: TStringField
FieldName = 'Name'
Size = 24
end
object Table1Capital: TStringField
FieldName = 'Capital'
Size = 24
end
object Table1Continent: TStringField
CustomConstraint = 'X = '#39'South America'#39' OR X = '#39'North America'#39
ConstraintErrorMessage = 'Country is not in the American Continent'
DefaultExpression = #39'South America'#39
FieldName = 'Continent'
Size = 24
end
object Table1Area: TFloatField
FieldName = 'Area'
end
object Table1Population: TFloatField
FieldName = 'Population'
end
end
object Table2: TTable
Active = True
DatabaseName = 'DBDEMOS'
TableName = 'animals.dbf'
Left = 80
Top = 232
object Table2NAME: TStringField
FieldName = 'NAME'
Size = 10
end
object Table2SIZE: TSmallintField
FieldName = 'SIZE'
end
object Table2WEIGHT: TSmallintField
FieldName = 'WEIGHT'
end
object Table2AREA: TStringField
FieldName = 'AREA'
end
object Table2BMP: TBlobField
FieldName = 'BMP'
BlobType = ftTypedBinary
Size = 1
end
end
end @@~~飛翔在天際的精靈~~@@
------
@@~~飛翔在天際的精靈~~@@ |
||
cyl
中階會員 發表:163 回覆:171 積分:66 註冊:2002-07-11 發送簡訊給我 |
unit Unit1; interface uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls, DBCtrls, StdCtrls, Mask, DB, Grids, DBGrids, DBTables; type
TForm1 = class(TForm)
Table1: TTable;
Table2: TTable;
DBGrid1: TDBGrid;
DataSource1: TDataSource;
Table1F_DIV: TStringField;
Table1F_DIV1: TStringField;
Table1F_NAME: TStringField;
Table1F_ID: TStringField;
Table1F_BORN: TStringField;
Table1F_INDATE: TStringField;
Table1F_INWORK: TStringField;
Table1F_POSIB: TStringField;
Table1F_DEGREE: TStringField;
Table1F_AC: TStringField;
Table1F_ACNO: TStringField;
Table1F_IDIV: TStringField;
Table1F_INAME: TStringField;
Table1F_KDIV: TStringField;
Table1F_KNAME: TStringField;
Table1F_ADDR1: TStringField;
Table1F_ADDR2: TStringField;
Table1F_TEL1: TStringField;
Table1F_TEL2: TStringField;
Table1F_BBCALL: TStringField;
Table1F_CALL: TStringField;
Table1F_GROUPP: TStringField;
Table1F_GROUP: TFloatField;
Table1F_LABELP: TStringField;
Table1F_HEAL: TFloatField;
Table1F_LABEL: TFloatField;
Table1F_BASEI: TFloatField;
Table1F_BASEO: TFloatField;
Table1F_IN: TStringField;
Table1F_INEND: TStringField;
Table1F_ACCNO: TStringField;
Table1F_PART1: TStringField;
Table1F_PART2: TStringField;
Table1F_PART3: TStringField;
Table1F_YEAR: TStringField;
Table1F_MONTH: TStringField;
Table1F_CHDATE: TStringField;
Label1: TLabel;
DBEdit1: TDBEdit;
DataSource2: TDataSource;
DBNavigator1: TDBNavigator;
Button1: TButton;
Table2F_ID: TStringField;
Table2F_NAME: TStringField;
Table2F_BORN: TStringField;
Table2F_TEL: TStringField;
Table2F_ZIP: TStringField;
Table2F_ADDR: TStringField;
procedure DBGrid1CellClick(Column: TColumn);
procedure FormActivate(Sender: TObject);
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end; var
Form1: TForm1; implementation {$R *.dfm} procedure TForm1.DBGrid1CellClick(Column: TColumn);
begin
table2.Edit ;
dbedit1.text:=table1.fieldbyname('f_id').asstring;
end; procedure TForm1.FormActivate(Sender: TObject);
begin
table1.Open;
table2.Open;
end; procedure TForm1.Button1Click(Sender: TObject);
begin
table1.close;
table2.close;
end; end. 奇怪不是跟你樣嗎??真的游標回到dbedit值又回到原來了??
|
||
jieshu
版主 發表:42 回覆:894 積分:745 註冊:2002-04-15 發送簡訊給我 |
引言: 請問我有一個dbedit,我要從dbgrid中點選一筆資料,然後把這筆資料帶到dbedit ex dbedit1.text:=table1.fieldsbyanme('a').asstring; 但是當我把游標focus回dbedit時,值又改回原值了,這是為什麼?? 然到一定要這樣寫 table2.fieldsbyanme('a').asstring:=table1.fieldsbyanme('a').asstring; 但是此時的dbedit.text並沒有改變 還要再加上 dbedit1.text:=table1.fieldsbyanme('a').asstring; 而且每次在給值時還要 table2.edit; 所以我的程式碼為 table2.edit; table2.fieldsbyanme('a').asstring:=table1.fieldsbyanme('a').asstring; dbedit1.text:=table1.fieldsbyanme('a').asstring; 為什麼要這麼麻煩呢?? 不是db原件嗎?? why?? ps:db是db3DBGrid和DBEdit都設好資料關聯屬性,根本就不需要再做任何動作,即可在DBGrid移到哪一筆DBEdit自動顯示哪一筆那一個欄位的值,DBEdit修改後,當然也是不需要做什麼事,DBGrid就會跟著改過。
------
人生有夢,逐夢而行 人若為善,福雖未至,禍已遠離 人若為惡,禍雖未至,福已遠離 http://www.taconet.com.tw/jieshu/ |
||
cyl
中階會員 發表:163 回覆:171 積分:66 註冊:2002-07-11 發送簡訊給我 |
[/quote]
DBGrid和DBEdit都設好資料關聯屬性,根本就不需要再做任何動作,即可在DBGrid移到哪一筆DBEdit自動顯示哪一筆那一個欄位的值,DBEdit修改後,當然也是不需要做什麼事,DBGrid就會跟著改過。
|
||
andersonhsieh
版主 發表:33 回覆:531 積分:439 註冊:2002-06-10 發送簡訊給我 |
|||
cyl
中階會員 發表:163 回覆:171 積分:66 註冊:2002-07-11 發送簡訊給我 |
|||
andersonhsieh
版主 發表:33 回覆:531 積分:439 註冊:2002-06-10 發送簡訊給我 |
本站聲明 |
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。 2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。 3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇! |