Delphi Pages Forums  

Go Back   Delphi Pages Forums > Delphi Forum > DB-Aware

Lost Password?

Reply
 
Thread Tools Display Modes
  #1  
Old 02-01-2007, 05:07 AM
A-slave A-slave is offline
Member
 
Join Date: Dec 2006
Posts: 48
Default dbgrid

Hi!
Problem is this:

I have two grids dbgrid1 and dbgrid2 and one button
when I click the button I have code that records from dbgrid1 put also in dbgrid2 ...this is ok , but if I click again, the same records will be in dbgrid2...
and in dbgrid2 i will have the same records as time as i press the button.
I want that when to click the button for the second and third time to do nothing...
Reply With Quote
  #2  
Old 02-01-2007, 05:59 AM
tomu tomu is offline
Senior Member
 
Join Date: May 2002
Posts: 186
Default RE: dbgrid

I'm not exaclt sure what you want. It you just want some code in a button press event to only happen once, try this:

unit Unit1;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;

type
TForm1 = class(TForm)

Button1: TButton;
procedure Button1Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
fDoneIt : boolean;
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation


{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
begin
if fDoneIt then exit;
ShowMessage('You will only see this once!'); // Put your grid code here.
fDoneIt := true;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
fDoneIt := false;
end;

end.
Reply With Quote
  #3  
Old 02-01-2007, 08:48 AM
Jasser Jasser is offline
Moderator
 
Join Date: Jan 2005
Location: Saudi Arabia
Posts: 5,059
Default RE: dbgrid

When the button is clicked use "Locate" method to search the second grid dataset for that record, and if it's not there then move the record to the other grid, otherwise display a message of do something. Your code should be something like this:

[DELPHI]var
pBM : TBookmark;
begin
pBM := DBGrid2.DataSource.DataSet.GetBookmark;

DBGrid2.DataSource.DataSet.DisableControls;

if DBGrid2.DataSource.DataSet.Locate('TheField','TheV alue',[]) then begin
Showmessage('You can not move the record again');
end else begin
//Move the record here.
end;

DBGrid2.DataSource.DataSet.GotoBookmark(pBM);

DBGrid2.DataSource.DataSet.EnableControls;[/DELPHI]

Regards,
Abdulaziz Jasser
Reply With Quote
  #4  
Old 02-03-2007, 03:50 AM
jdg jdg is offline
Senior Member
 
Join Date: Sep 2003
Posts: 1,063
Default RE: dbgrid

Your question is unclear.
If it has not been answered, perhaps clarification would help you get your answer.

jdg.ho

I love this forum. Your generosity is wonderful.
Reply With Quote
  #5  
Old 02-04-2007, 10:20 AM
Jasser Jasser is offline
Moderator
 
Join Date: Jan 2005
Location: Saudi Arabia
Posts: 5,059
Default RE: dbgrid

A-slave,

Was my reply to you helpful? If so, please accept.

Regards,
Abdulaziz Jasser
Reply With Quote
  #6  
Old 02-05-2007, 02:38 AM
A-slave A-slave is offline
Member
 
Join Date: Dec 2006
Posts: 48
Default RE: dbgrid

I will try to work alone...and the answers befor help to me very much to have some ideas...
then i will show yoh what i have workd
Reply With Quote
  #7  
Old 02-05-2007, 11:37 AM
Jasser Jasser is offline
Moderator
 
Join Date: Jan 2005
Location: Saudi Arabia
Posts: 5,059
Default RE: dbgrid

A-slave,

Then why did you accept an answer that did not help?

Regards,
Abdulaziz Jasser
Reply With Quote
  #8  
Old 02-06-2007, 02:14 AM
jdg jdg is offline
Senior Member
 
Join Date: Sep 2003
Posts: 1,063
Default RE: dbgrid

Lol.
Because there is no justice in this forum & hardly any respect for who gets the point.

It is important to those that answer your question, who gets the point.

jdg.ho

I love this forum. Your generosity is wonderful.
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 06:20 AM.


Powered by vBulletin® Version 3.8.8
Copyright ©2000 - 2019, vBulletin Solutions, Inc.