Link to home
Start Free TrialLog in
Avatar of yehiaeg
yehiaegFlag for Egypt

asked on

Value List Editor

hello,

was using the value list editor, i wanted to change the color of the cell (first column) to clRed when the cell (second column) is edited , i tried this code in the DrawCellEvent :

if  (gdFocused in State) then begin
     vle.Canvas.Brush.Color := clRed;
    vle.Canvas.FillRect(Rect);
end;
Avatar of LRHGuy
LRHGuy

This works for me, but you have to have the goRowSelect option turned on...

procedure TForm2.vleDrawCell(Sender: TObject; ACol,
  ARow: Integer; Rect: TRect; State: TGridDrawState);
var
  T:string;
  Item:TItemProp;
begin
if (ARow=vle.Row)
and (ACol=0)
then begin
     vle.Canvas.Brush.Color := clRed;
    vle.Canvas.FillRect(Rect);
    Item:=vle.ItemProps[vle.Row];
    if (Item<>nil) and (Item.KeyDesc<> '') then
      T:=Item.KeyDesc
    else
      T:=vle.Cells[ACol, ARow];
    vle.Canvas.TextRect(Rect,Rect.Left+2,Rect.Top+2,T);
end;
end;


  object vle: TValueListEditor
    Left = 16
    Top = 108
    Width = 306
    Height = 144
    Options = [goFixedVertLine, goFixedHorzLine, goVertLine, goHorzLine, goDrawFocusSelected, goColSizing, goEditing, goRowSelect, goThumbTracking]
    Strings.Strings = (
      'one=two'
      'three=four'
      'five=six')
    TabOrder = 2
    OnDrawCell = vleDrawCell
  end
Avatar of yehiaeg

ASKER

yea but when goRowSelect is on, i can't edit the second column
Did you set DefaultDrawing to False? This is required if you don't want the editor to draw over your own drawings. :-)
From what I can tell, setting DefaultDrawing to false means you MUST draw the complete cell, everytime. Leaving it at True will have the component draw the cell, then call the onDrawCell event. The event method is called after the cell is drawn (DefaultDrawing=true) or after the drawing is skipped (DefaultDrawing=false).

My example leaves DefaultDrawing=true, then only draws column 0 of the active row.
Avatar of yehiaeg

ASKER

guys, it draw correctly when setting goRowselect to true, but the PROBLEM IS i can't edit anything now in the cells, cause when setting goRowSelect to True goAlwaysShowEditor is turned to False automatically,

when setting goRowSelect to false, i can now edit any cell but the drawcell event won't work,

any ideas?
ASKER CERTIFIED SOLUTION
Avatar of LRHGuy
LRHGuy

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of yehiaeg

ASKER

thanks man, keep answering, have lots of other questions about value list editor