 |
BorlandTalk.com Borland discussion newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Bpk. Adi Wira Kusuma Guest
|
Posted: Wed Jan 18, 2006 4:09 pm Post subject: How to keep position row in dbgrid? |
|
|
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
|
Posted: Wed Jan 18, 2006 5:07 pm Post subject: Re: How to keep position row in dbgrid? |
|
|
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
|
Posted: Wed Jan 18, 2006 6:18 pm Post subject: Re: How to keep position row in dbgrid? |
|
|
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 |
|
 |
|
|
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
|
|