BorlandTalk.com Forum Index BorlandTalk.com
Borland discussion newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

How to keep position row in dbgrid?

 
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> Delphi Databases (ADO)
View previous topic :: View next topic  
Author Message
Bpk. Adi Wira Kusuma
Guest





PostPosted: Wed Jan 18, 2006 4:09 pm    Post subject: How to keep position row in dbgrid? Reply with quote



I use TAdoQuery, I can not refresh data with "Refresh" method. So I've to
use "Close" & "Open" method to refresh data. But I've a problem, When I do
it, At DBGrid, position of the row is back to top, and Horizontal Scroolbar
is back to left.

Although, I want position of the row, and Horizontal Scroolbar are not
change when I refresh data. How is the best solution for my problems?


Back to top
Kevin Frevert
Guest





PostPosted: Wed Jan 18, 2006 5:07 pm    Post subject: Re: How to keep position row in dbgrid? Reply with quote



Adi,

This is what we use (copied from our library, internal documentation
removed)

procedure SmartRefresh(DataSet :TDataSet; KeyFieldName :String);
var
AValue :String; {for debugging}
begin
if NOT(DataSet.Active) then
DataSet.Open;
if (DataSet.Active) and NOT(DataSet.IsEmpty) then
begin
if (Length(KeyFieldName) < 1) then
KeyFieldName := DataSet.Fields[0].FieldName; {if no field name is
passed, use first field}
AValue := DataSet.FieldByName(KeyFieldName).AsString;
DataSet.DisableControls;
try
DataSet.Close;
DataSet.Open;
DataSet.Locate(KeyFieldName,AValue,[]);
finally { wrap up }
DataSet.EnableControls;
end; { try/finally }
end;
end;

Good luck,
krf

"Bpk. Adi Wira Kusuma"
Quote:
I use TAdoQuery, I can not refresh data with "Refresh" method. So I've to
use "Close" & "Open" method to refresh data. But I've a problem, When I do
it, At DBGrid, position of the row is back to top, and Horizontal
Scroolbar
is back to left.

Although, I want position of the row, and Horizontal Scroolbar are not
change when I refresh data. How is the best solution for my problems?





Back to top
Steve Zimmelman
Guest





PostPosted: Wed Jan 18, 2006 6:18 pm    Post subject: Re: How to keep position row in dbgrid? Reply with quote



You can either pass in the FldValue of the keyfield or the fieldname for the
current record.

Usage:

RefreshQuery(AdoQuery1,Null,'ID');

or

RefreshQuery(AdoQuery1,AdoQuery1.FieldByName('ID').AsInteger);


Procedure RefreshQuery(Qry:TADOQuery
;AFldValue:Variant;FieldName:String='');
Var
vValue : Variant ;

Begin
vValue := Null ;
If (FieldName <> '') And Qry.Active Then Begin
If AFldValue <> Null Then Begin
vValue := AFldValue ;
End Else If (Qry.FindField(FieldName) <> Nil) Then Begin
vValue := Qry.FieldByName(FieldName).Value ;
End;
End;
Try
Qry.DisableControls ;

If Qry.Active Then
Qry.Requery
Else
Qry.Open ;

If (vValue <> Null) Then Begin
// Older versions of ADO raise an error if the locate fails.
Try
Qry.Locate(FieldName,vValue,[]);
Except
End;
End;
Finally
Qry.EnableControls ;
End;
End;

"Bpk. Adi Wira Kusuma" <adi_wira_kusuma (AT) yahoo (DOT) com.sg> wrote

Quote:
I use TAdoQuery, I can not refresh data with "Refresh" method. So I've to
use "Close" & "Open" method to refresh data. But I've a problem, When I do
it, At DBGrid, position of the row is back to top, and Horizontal
Scroolbar
is back to left.

Although, I want position of the row, and Horizontal Scroolbar are not
change when I refresh data. How is the best solution for my problems?





Back to top
Display posts from previous:   
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> Delphi Databases (ADO) All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.