Re: TZF - TzGrid Colors
Marie Vihonsky <[email protected]> Wed, 05 Nov 2003 13:11:51 -0500
| Newsgroups | gmane.comp.lang.delphi.topaz |
|---|---|
| Message-ID | <[email protected]> |
Hi Bob, I did look at your 'project' and see what you mean but I didn't have any luck trying to 'fix it'. I have a pressing project at the moment and can't work on it further but I do have some thoughts. Linking the change to the recno may not be the way to go. I would suggest looking at determining the 'current row' being viewed in the grid and the 'current cell'. It may also have to do with 'refreshgrid' not sure. You might also want to check the Topaz source for the tzgrid to see if there are any hints there, especially since the grid normally shows a deleted record with the full row in red. When I ran your EXE, the up & down arrows worked but there was no navigator. I tried bringing it into my Delphi and got an error since I'm using D5 and you are using D6. I ended up creating my own version to play with. I may get back to this later since I like the underlying thought of showing the full row in a different color when the row is selected plus the current cell in another color. If you do figure it out, let me know. Marie [email protected] wrote: > > >Hi Bob, > > >I think the 'Table1size' variable refers to a 'Field' in the grid. So > >you need to substitute a valid field reference from your database. > > >Here's some alternate code for changing colors: > >----------------------------------------------------- > >Change Color of Grid Cell > > <SNIP> > > >Maybe one of these, or a combination, will get you what you want. > > >Marie > ______________________________________________________ > ______________________________________________________ > > > > > Thanks Marie - > That hit the spot. I modified one of your examples slightly > and I moved very close to my goal. The following code will make the > "current row" a different color, and the selected field an even different > color. There is a problem with scrolling, which is explained after the > code. > > > // &&&&&&&&&&&&&&&&&&&& > unit U_Main; > > interface > > uses > Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, > Dialogs, Grids, DBGrids, atzgrids, DB, tzprimds, ucommon, utzcds, utzfds; > > type > TForm1 = class(TForm) > TzDbf1: TTzDbf; > DataSource1: TDataSource; > TzGrid1: TTzGrid; > procedure FormActivate(Sender: TObject); > procedure TzGrid1ChangeColorsEvent(Sender: TObject; curRow: Integer; > var IndicatorColor, CellColor, CellTextColor, HiliteColor, > HiliteTextColor, DeletedColor, DeletedTextColor: TColor); > procedure TzDbf1AfterScroll(DataSet: TDataSet); > private > { Private declarations } > public > { Public declarations } > globCurrentMasterRecordNo:LongInt; > end; > > var > Form1: TForm1; > > implementation > > {$R *.dfm} > > procedure TForm1.FormActivate(Sender: TObject); > begin > tzDBF1.DbfFileName:='.\Games.dbf'; > tzDBF1.Active:=True; > end; > > procedure TForm1.TzGrid1ChangeColorsEvent(Sender: TObject; curRow: Integer; > var IndicatorColor, CellColor, CellTextColor, HiliteColor, > HiliteTextColor, DeletedColor, DeletedTextColor: TColor); > begin > if tzDBF1.recNo=globCurrentMasterRecordNo then > begin > CellColor:=$0033FFFF; > DeletedColor:=clRed; > HiliteColor:=$00ffff01; > CellTextColor:=clBLACK; > HiliteTextColor:=clBLACK; > end > else > begin > CellColor:=$00B3F8FF; > HiliteColor:=$00B3F8FF; > CellTextColor:=clBlack; > HiliteTextColor:=clBlack; > end; > end; > > procedure TForm1.TzDbf1AfterScroll(DataSet: TDataSet); > begin > globCurrentMasterRecordNo:=tzDBF1.RecNo; > end; > > end. > // &&&&&&&&&& end of code &&&&&&&& > > > > There is still one problem. Whenever you use the keyboard > up and down arrow to navigate thru the dataset, everything > works fine. But if you use > the up and down arrows on the grid scroll bar, it does not > work as desired ....Also, if you put a SKIP button on > the form it does not work as desired ... its close, but not quite. > Must have something to do with the way > the "events occur". > > In case you are further interested, you > can download the project files, a DBF file and an EXE file > in the form of a zip file at: > > http://www.mindspring.com/~au_fan/rowColor/ > > > Thanks so much for the assistance, > Bob Watson > > ______________________________________________________ > ______________________________________________________ > > Hi Bob, > > I think the 'Table1size' variable refers to a 'Field' in the grid. So > you need to substitute a valid field reference from your database. > > Here's some alternate code for changing colors: > ----------------------------------------------------- > Change Color of Grid Cell > > procedure TCountForm1.TzGrid1DrawDataCell(Sender: TObject; > const Rect: TRect; Field: TField; State: TGridDrawState); > var s : array[0..255] of char; > FieldAsString : string; > begin > with (sender as TTzGrid).canvas do begin > FieldAsString := Field.AsString; > if GetDBaseType(Field) in ['N'] then {a number} > Brush.Color := clAqua; > FillRect(Rect); > ExtTextOut(Handle, Rect.Left + 2,Rect.Top + 2, > ETO_OPAQUE or ETO_CLIPPED, @Rect, > StrPCopy(S, FieldAsString), Length(FieldAsString), nil); > end; > end; > -------------------------------------------- > Display a DBGrid column in a different color > > # First, put the DefaultDrawing property of the DBGrid to False > # Later, put this code into OnDrawDataCell event of the DBGrid: > > procedure TForm1.DBGrid1DrawDataCell(Sender: TObject; const Rect: TRect; > Field: TField; State: TGridDrawState); > begin > { NOMBRE this the field name to paint in a diferent color } > if Field.FieldName = 'NOMBRE' then > (Sender as TDBGrid).Canvas.Font.Color := clRed; > (Sender as TDBGrid).Canvas.TextRect(Rect, Rect.Left + 2, > Rect.Top + 2, Field.AsString); > end; > ------------------------------------------------------------ > Alternating colors in a grid > > procedure TForm1.TzGrid1ChangeColorsEvent(Sender: TObject; curRow: Integer; > var IndicatorColor, CellColor, CellTextColor, HiliteColor, > HiliteTextColor, DeletedColor, DeletedTextColor: TColor); > begin > > With (sender as TTzGrid) do begin > if (CurRow MOD 2)=0 then begin > CellColor:=$00B3F8FF; > HiliteColor:=$00B3F8FF; > CellTextColor:=clBlack; > HiliteTextColor:=clBlack; > end > else begin > CellColor:=$00E1E1C6; > HiliteColor:=$00E1E1C6; > CellTextColor:=clBlack; > HiliteTextColor:=clBlack; > end; > end; > if TzDbf1.Deleted then begin > if (curRow MOD 2)=0 then begin > DeletedColor:=$00B3F8FF; > HiliteColor:=$00B3F8FF; > CellTextColor:=clBlack; > HiliteTextColor:=clBlack; > end > else begin > DeletedColor:=$00E1E1C6; > HiliteColor:=$00E1E1C6; > CellTextColor:=clBlack; > HiliteTextColor:=clBlack; > end; > end; > end; > ---------------------------------------------------- > > Maybe one of these, or a combination, will get you what you want. > > Marie > > > > --^---------------------------------------------------------------- This email was sent to: [email protected] EASY UNSUBSCRIBE click here: http://topica.com/u/?clvXPN.a5kvff.Z2NsZHQt Or send an email to: [email protected] TOPICA - Start your own email discussion group. FREE! http://www.topica.com/partner/tag02/create/index2.html --^----------------------------------------------------------------