Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

TDBGrid Cell click problem

Status
Not open for further replies.

msgopala

Programmer
Oct 30, 2008
43
0
0
US
Have a TDBGrid that displays history for a customer. There may be one or more rows for a single customer. There is a column that displays an image and when the image is clicked it pulls up a pdf file stored in the db for this record.

My problem is that cell remains in the clicked state even after the user moves on to a different record and when the user enters the hostory tab for the second customer the focus is already on the image and clicking it does not pull up the pdf but the image turns into the words "memo".

The only way around it is to click somewhere else on the grid and then re-click the cell with the image to pull up the pdf file.

I have tried refresh, focus, focus cell on the history tab enter and exit but so far have not had success.

Thanks in dvance for your suggestions
 
try to draw the images in OnDrawColumnCell or OnDrawDataCell
Using these methods to draw the grid gives you a good control over what is happening during the drawing of the cells

If you have used these methods already please let us see your code
 
I do have a DrawColumnCell proc and a OnClick event.


~**DrawColumncell**~

procedure TBrowsePolicies.TransactionsGridDrawColumnCell(Sender: TObject;const Rect: TRect;
DataCol: Integer; Column: TColumnEh;State: TGridDrawState);
var
bitmap : TBitMap;
fixrect : TRect;
bmpHeight, bmpLeft : integer;
Imgindex : integer;
begin
inherited;
fixrect := Rect;
{$IFNDEF NCGMRate}
if Column.FieldName = 'AIMAGE' then
begin
TransactionsGrid.Canvas.Brush.Color := clWindow;
TransactionsGrid.Canvas.FillRect(Rect);

if not Datamodule.History.FieldByname('AIMAGE').IsNull then
begin
imgIndex := 0;
bitmap := TBitMap.Create;
try
THImageList.GetBitMap(ImgIndex,Bitmap);
bmpHeight := (Rect.Bottom - Rect.Top);
FixRect.Right := Rect.Left + bmpHeight;
TransactionsGrid.Canvas.StretchDraw(FixRect,Bitmap);
finally
BitMap.Free;
end;
end;
end;

if Column.FieldName = 'BIMAGE' then
begin
TransactionsGrid.Canvas.Brush.Color := clWindow;
TransactionsGrid.Canvas.FillRect(Rect);

if not Datamodule.History.FieldByname('BIMAGE').IsNull then
begin
imgIndex := 1;
bitmap := TBitMap.Create;
try
THImageList.GetBitMap(ImgIndex,Bitmap);
bmpHeight := (Rect.Bottom - Rect.Top);
FixRect.Right := Rect.Left + bmpHeight;
TransactionsGrid.Canvas.StretchDraw(FixRect,Bitmap);
finally
BitMap.Free;
end;
end;
end;

if Column.FieldName = 'CIMAGE' then
begin
TransactionsGrid.Canvas.Brush.Color := clWindow;
TransactionsGrid.Canvas.FillRect(Rect);

if not Datamodule.History.FieldByname('CIMAGE').IsNull then
begin
imgIndex := 2;
bitmap := TBitMap.Create;
try
THImageList.GetBitMap(ImgIndex,Bitmap);
bmpHeight := (Rect.Bottom - Rect.Top);
FixRect.Right := Rect.Left + bmpHeight;
TransactionsGrid.Canvas.StretchDraw(FixRect,Bitmap);
finally
BitMap.Free;
end;
end;
end;
{$ELSE}
if Column.FieldName = 'DIMAGE' then
begin
TransactionsGrid.Canvas.Brush.Color := clWindow;
TransactionsGrid.Canvas.FillRect(Rect);

if not Datamodule.History.FieldByname('DIMAGE').IsNull then
begin
imgIndex := 3;
bitmap := TBitMap.Create;
try
THImageList.GetBitMap(ImgIndex,Bitmap);
bmpHeight := (Rect.Bottom - Rect.Top);
FixRect.Right := Rect.Left + bmpHeight;
TransactionsGrid.Canvas.StretchDraw(FixRect,Bitmap);
finally
BitMap.Free;
end;
end;
end;
___________________________________________________________

~**GridCellClick**~

procedure TBrowsePolicies.TransactionsGridCellClick(Column: TColumnEh);
var
BStream : TStream;
FStream : TFileStream;
QRPDevice : TQRPHandler;
begin
inherited;
{$IFNDEF NCGMRate}
if (Upper(TransactionsGrid.SelectedField.DisplayLabel) = 'AIMAGE') and
(not Datamodule.History.FieldByname('AIMAGE').IsNull) then
begin
BStream := Datamodule.History.CreateBlobStream(Datamodule.History.FieldByName(AIMAGE'),bmRead);
try
BStream.Seek(0, soFromBeginning);
with TFileStream.Create(ExtractFilePath(Application.ExeName)+'APAGE.PDF',fmCreate) do
try
CopyFrom(BStream, BStream.Size);
finally
Free
end;
finally
BStream.Free;
end;

PDFFileViewer := TPDFFileViewer.Create(Application);
PDFFileViewer.PDFFile.LoadFile(ExtractFilePath(Application.ExeName)+'APAGE.PDF');
PDFFileViewer.ShowModal;
PDFFileViewer.PDFFile.Destroy;
// TransactionsGrid.Refresh;
//IntToStr(transactionsGrid.Col - 4);
// TranHistTab.
end
else
If (Upper(TransactionsGrid.SelectedField.DisplayLabel) = AIMAGE') and
Datamodule.History.FieldByname(AIMAGE').IsNull then
raise Exception.Create('No Dec Page to display.');

if (Upper(TransactionsGrid.SelectedField.DisplayLabel) = 'BIMAGE') and
(not Datamodule.History.FieldByname('BIMAGE').IsNull) then
begin
BStream := Datamodule.History.CreateBlobStream(Datamodule.History.FieldByName('BIMAGE'),bmRead);
try
BStream.Seek(0, soFromBeginning);
with TFileStream.Create(ExtractFilePath(Application.ExeName)+'BPAGE.PDF',fmCreate) do
try
CopyFrom(BStream, BStream.Size);
finally
Free
end;
finally
BStream.Free;
end;

PDFFileViewer := TPDFFileViewer.Create(Application);
PDFFileViewer.PDFFile.LoadFile(ExtractFilePath(Application.ExeName)+'BPAGE.PDF');
PDFFileViewer.ShowModal;
PDFFileViewer.PDFFile.Destroy;
TransactionsGrid.Refresh;
end
else
If (Upper(TransactionsGrid.SelectedField.DisplayLabel) = 'BIMAGE') and Datamodule.History.FieldByname('BIMAGE').IsNull then
raise Exception.Create('No Billing Notice to display.');

if (Upper(TransactionsGrid.SelectedField.DisplayLabel) = 'CIMAGE') and
(not Datamodule.History.FieldByname('CIMAGE').IsNull) then
begin
BStream := Datamodule.History.CreateBlobStream(Datamodule.History.FieldByName('CIMAGE'),bmRead);
try
BStream.Seek(0, soFromBeginning);
with TFileStream.Create(ExtractFilePath(Application.ExeName)+'CPAGE.PDF',fmCreate) do
try
CopyFrom(BStream, BStream.Size);
finally
Free
end;
finally
BStream.Free;
end;

PDFFileViewer := TPDFFileViewer.Create(Application);
PDFFileViewer.PDFFile.LoadFile(ExtractFilePath(Application.ExeName)+'CPAGE.PDF');
PDFFileViewer.ShowModal;
PDFFileViewer.PDFFile.Destroy;
TransactionsGrid.Refresh;
end
else
If (Upper(TransactionsGrid.SelectedField.DisplayLabel) = 'CIMAGE') and Datamodule.History.FieldByname('CIMAGE').IsNull then
raise Exception.Create('No Notice to display.');
{$ELSE}
if (Upper(TransactionsGrid.SelectedField.DisplayLabel) = 'DIMAGE') and
(not Datamodule.History.FieldByname('DIMAGE').IsNull) then
begin
BStream := Datamodule.History.CreateBlobStream(Datamodule.History.FieldByName('DIMAGE'),bmRead);
try
BStream.Seek(0, soFromBeginning);
with TFileStream.Create(ExtractFilePath(Application.ExeName)+'DPAGE.PDF',fmCreate) do
try
CopyFrom(BStream, BStream.Size);
finally
Free
end;
finally
BStream.Free;
end;

PDFFileViewer := TPDFFileViewer.Create(Application);
PDFFileViewer.PDFFile.LoadFile(ExtractFilePath(Application.ExeName)+'DPAGE.PDF');
PDFFileViewer.ShowModal;
PDFFileViewer.PDFFile.Destroy;
TransactionsGrid.Refresh;
end
end;


Thanks


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top