双击dbgrid时,如何不包括title? |
答題得分者是:malanlk
|
luowy651
高階會員 發表:257 回覆:313 積分:114 註冊:2003-04-09 發送簡訊給我 |
各位大大好:
小弟有一问题,我在dbgrid的 DblClick 中写有code,但我却发现我在双击title时,DblClick也会起作用,而我在OnTitleClick中又另有code, 能否让它在双击title时不起作用? |
malanlk
尊榮會員 發表:20 回覆:694 積分:577 註冊:2004-04-19 發送簡訊給我 |
unit Unit1;
interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, Grids, DBGrids; type TForm1 = class(TForm) DBGrid1: TDBGrid; procedure DBGrid1DblClick(Sender: TObject); procedure DBGrid1TitleClick(Column: TColumn); private { Private declarations } public { Public declarations } end; var Form1: TForm1; implementation {$R *.dfm} procedure TForm1.DBGrid1DblClick(Sender: TObject); begin ShowMessage('AA'); end; procedure TForm1.DBGrid1TitleClick(Column: TColumn); begin ShowMessage('BB' IntToStr(COlumn.Index)); end; end. 我用這段程式去試並沒有您說的情況... |
luowy651
高階會員 發表:257 回覆:313 積分:114 註冊:2003-04-09 發送簡訊給我 |
非常感谢malanlk大大的关注小弟的问题
确实,您的例程中并无这种情况产生,但如果您再增加一个adotable1和DataSource1,随便连一张table,整个code如下,就会产生我所说的问题(我在TitleClick中的code,目的是为了可以在title上单击时,产生正反向的排序): unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, Grids, DBGrids, DB, ADODB; type TForm1 = class(TForm) DBGrid1: TDBGrid; DataSource1: TDataSource; ADOTable1: TADOTable; procedure DBGrid1DblClick(Sender: TObject); procedure DBGrid1TitleClick(Column: TColumn); procedure FormCreate(Sender: TObject); private { Private declarations } public { Public declarations } end; var Form1: TForm1; implementation {$R *.dfm} procedure TForm1.DBGrid1DblClick(Sender: TObject); begin ShowMessage('AA'); end; procedure TForm1.DBGrid1TitleClick(Column: TColumn); begin case Column.Index of 0 : ; 5 : else if adotable1.Sort = Column.FieldName ' ASC' then adotable1.Sort := Column.FieldName ' DESC' // Sort by Clicked Column Desc else adotable1.Sort := Column.FieldName ' ASC'; // Sort by Clicked Column Asc end; end; procedure TForm1.FormCreate(Sender: TObject); begin end; end. |
luowy651
高階會員 發表:257 回覆:313 積分:114 註冊:2003-04-09 發送簡訊給我 |
或者只要去掉下面 ShowMessage('BB'+IntToStr(COlumn.Index));
这一句,也会出现我所言的情况 ===================引 用 malanlk 文 章=================== unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, Grids, DBGrids; type TForm1 = class(TForm) DBGrid1: TDBGrid; procedure DBGrid1DblClick(Sender: TObject); procedure DBGrid1TitleClick(Column: TColumn); private { Private declarations } public { Public declarations } end; var Form1: TForm1; implementation {$R *.dfm} procedure TForm1.DBGrid1DblClick(Sender: TObject); begin ShowMessage('AA'); end; procedure TForm1.DBGrid1TitleClick(Column: TColumn); begin ShowMessage('BB' IntToStr(COlumn.Index)); end; end. 我用這段程式去試並沒有您說的情況... |
malanlk
尊榮會員 發表:20 回覆:694 積分:577 註冊:2004-04-19 發送簡訊給我 |
unit Unit1;
interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, Grids, DBGrids; type TForm1 = class(TForm) DBGrid1: TDBGrid; procedure DBGrid1DblClick(Sender: TObject); procedure DBGrid1TitleClick(Column: TColumn); private { Private declarations } public { Public declarations } end; var Form1: TForm1; implementation {$R *.dfm} var IsTitleClick: Boolean = False; procedure TForm1.DBGrid1DblClick(Sender: TObject); begin if IsTitleClick then begin IsTitleClick := False; Exit; end; ShowMessage('AA'); end; procedure TForm1.DBGrid1TitleClick(Column: TColumn); begin Caption := 'BB' IntToStr(COlumn.Index); //ShowMessage('BB' IntToStr(COlumn.Index)); IsTitleClick := True; end; 這樣就可以了! |
luowy651
高階會員 發表:257 回覆:313 積分:114 註冊:2003-04-09 發送簡訊給我 |
本站聲明 |
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。 2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。 3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇! |