| |

VerySource

 Forgot password?
 Register
Search
View: 1400|Reply: 6

Help: CXGRID realizes the effect of zebra crossing.

[Copy link]

1

Threads

4

Posts

4.00

Credits

Newbie

Rank: 1

Credits
4.00

 China

Post time: 2020-11-26 23:00:01
| Show all posts |Read mode
My code is as follows:
procedure TForm1.cxGrid1DBTableView1CustomDrawCell(
  Sender: TcxCustomGridTableView; ACanvas: TcxCanvas;
  AViewInfo: TcxGridTableDataCellViewInfo; var ADone: Boolean);
begin
  inherited;
if dm1.AdoDataSet.RecNo mod 2=0 then
begin
ACanvas.Canvas.Brush.Color :=clBlack;
end
else
begin
ACanvas.Canvas.Brush.Color:=clWhite;
end;
end;

After the program runs, the zebra crossing effect is not displayed, unless the color changes after the mouse clicks on the line.
Ask you how to set CXGRID or what code to achieve the perfect zebra crossing effect.
Reply

Use magic Report

0

Threads

5

Posts

4.00

Credits

Newbie

Rank: 1

Credits
4.00

 China

Post time: 2020-11-27 15:45:01
| Show all posts
For your reference:
   ARect:=AViewInfo.Bounds;
   ATextToDraw := AViewInfo.GridRecord.DisplayTexts[AViewInfo.Item.Index];
   val := VarAsType(AViewInfo.GridRecord.DisplayTexts[EmpGridChangeType.Index], varString);
   if val <>'on the job' then ACanvas.Canvas.Brush.Color := clRed;
   ACanvas.Canvas.FillRect(ARect);
   SetBkMode(ACanvas.Canvas.Handle, TRANSPARENT);
   ACanvas.DrawText(ATextToDraw, AViewInfo.Bounds, 0);

If not in a job, it is displayed in red
Reply

Use magic Report

1

Threads

4

Posts

4.00

Credits

Newbie

Rank: 1

Credits
4.00

 China

 Author| Post time: 2020-11-27 18:00:01
| Show all posts
But what I want is the effect of zebra crossing
Reply

Use magic Report

0

Threads

25

Posts

18.00

Credits

Newbie

Rank: 1

Credits
18.00

 United States

Post time: 2020-11-27 23:45:01
| Show all posts
Just change the conditions

procedure TForm1.cxGrid1DBTableView1CustomDrawCell(
  Sender: TcxCustomGridTableView; ACanvas: TcxCanvas;
  AViewInfo: TcxGridTableDataCellViewInfo; var ADone: Boolean);
begin
  inherited;
  if AViewInfo.RecordViewInfo.Index mod 2 = 0 then
    ACanvas.Canvas.Brush.Color :=clBlack;
  else
    ACanvas.Canvas.Brush.Color:=clWhite;
end;
Reply

Use magic Report

1

Threads

4

Posts

4.00

Credits

Newbie

Rank: 1

Credits
4.00

 China

 Author| Post time: 2020-11-28 08:00:01
| Show all posts
Thanks, the effect of zebra crossing can be achieved after the change
But a new problem appeared, that is: after pulling the scroll bar of cxgrid (for example: there are a total of 50 data, only 20 are displayed, and 30 data are not displayed, the scroll bar is turned down to display the following data), The effect of the zebra crossing is messed up. It should be one black and one white alternately, but after rolling, the phenomenon that should appear alternately becomes 5 white and one black or 4 white and one black. How can I explain?
Reply

Use magic Report

0

Threads

25

Posts

18.00

Credits

Newbie

Rank: 1

Credits
18.00

 China

Post time: 2020-11-28 09:15:01
| Show all posts
The above code is no problem, I have more than 3000 rows of data here are all normal. So you can change to a way that does not need to write any code:

Place a StyleRepository, set the Styles of your TableView to this StyleRepository, and then set the Styles ContentEven (even-numbered rows content) and ContentOdd (odd-numbered rows content) Color. The zebra crossing effect you want can also be achieved.
Reply

Use magic Report

1

Threads

4

Posts

4.00

Credits

Newbie

Rank: 1

Credits
4.00

 China

 Author| Post time: 2020-11-28 09:30:01
| Show all posts
Thank you very muchsupperman!
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list