Solved

PickList and ValueListEditor

Posted on 2004-08-10
8
3,103 Views
Last Modified: 2012-06-21
hello,

how can i set a cell text with esPickList style , i mean if i have a cell
with EditStyle esPickList,
and i chose an item from the picklist, how can i change the cell text
afterwards, i tried the TSetEditText event but  the "value" is read only

procedure TFrmMain.vleSetEditText(Sender: TObject; ACol, ARow: Integer;
const Value: String);
begin
if value = '<color>' then value := 'COLOR'; //error left side cannot be
assigned
end;

Thanks
Yehia

0
Comment
Question by:yehiaeg
  • 4
  • 3
8 Comments
 
LVL 12

Expert Comment

by:esoftbg
ID: 11769527
As you see:
> const Value: String);
const can not be changed.

The next code raises an exception EStackOverflow:
procedure TForm1.vleSetEditText(Sender: TObject; ACol, ARow: Integer; const Value: String);
begin
  if vle.Cells[ACol,ARow] = '<color>' then
    vle.Cells[ACol,ARow] := 'COLOR';
end;

but, the next code works fine:
procedure TForm1.vleDrawCell(Sender: TObject; ACol, ARow: Integer; Rect: TRect; State: TGridDrawState);
begin
  if vle.Cells[ACol,ARow] = '<color>' then
    vle.Cells[ACol,ARow] := 'COLOR';end;

emil
0
 

Author Comment

by:yehiaeg
ID: 11772203
well, this is not very neat to put the code in vleDrawCell, i  want my code fired only when changing the value of the cell to <color> , any other way ?
0
 
LVL 12

Expert Comment

by:esoftbg
ID: 11772941
but every time you leave the changed sell it is drawing: may be just what you need ?
0
 
LVL 12

Expert Comment

by:esoftbg
ID: 11772955
> sell
cell
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 7

Accepted Solution

by:
LRHGuy earned 125 total points
ID: 11773677
The problem arises from the fact that OnSetEditText is called whenever the user edits the field. The intent of the event was probably to allow what you are trying to do. The problem is, it's implemented wrong in the ValueListEditor, which is derived from the grideditor, where it is done right. The ValueListEditor event is overridden, after calling the grideditor method...it's the grid editor method that calls the OnSetEditText event if assigned. The ValueListEdit then "undoes" any changes, since the value passed is passed as a "const" and not a "var". (I believe it should hav been a "var"). SetEditText is also called whenever the cell value is being changed.

Anyway, the solution lies in playing a trick. Either fixing it in the draw routine, as shown by esoftbg, or other methods.

You might consider this:

in the SetEditText event, set a marker that says you need to change something:

if Value='<color>' then begin
  FixRow:=ARow;
  FixCol :=ACol;
end;

in the DrawCell event, make the change:

if (FixRow>=0) and (FixCol>=0) then begin
  vle.Cells[FixCol,FixRow] := 'COLOR';
  FixRow:=-1;
  FixCol:=-1;
end;

In FormCreate, initialize:

  FixRow:=-1;
  FixCol:=-1;

With this procedure, at least DrawCell will only fix it "once"...when detected by SetEditText.

I've played with it, and so far haven't found any other way that works. I believe the problem lies in a misimplementation of the SetEditText method of ValueListEditor.

Hope that helps!
0
 

Author Comment

by:yehiaeg
ID: 11773825
but also the DrawCell event fires all the time ( when form is hid and shown, or when i move a window across the cell, it's just not the right place to put my code),
here is an idea of what i want:

i have an item in the value list editor called Color, the ItemProp.EditStyle = csPickList,
the drop down list have an item called '<color'> , when i click on it the TcolorDialog shows prompting the user to select a color and the selected color is entered in the cell, something like this:

OnSetEditText Event -->
 if value = '<color>' then begin
     if dialogcolor.Execute = true then vle.Cells[acol,arow] := colortostring(dialogcolor.Color);
 end;
0
 
LVL 12

Expert Comment

by:esoftbg
ID: 11773866
Try this:

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, Grids, ValEdit, Spin;

type
  TForm1 = class(TForm)
    vle: TValueListEditor;
    Memo1: TMemo;
    Memo11: TMemo;
    Button1: TButton;
    SpinEdit: TSpinEdit;
    procedure vleSetEditText(Sender: TObject; ACol, ARow: Integer; const Value: String);
    procedure vleDrawCell(Sender: TObject; ACol, ARow: Integer; Rect: TRect; State: TGridDrawState);
    procedure Button1Click(Sender: TObject);
    procedure SpinEditExit(Sender: TObject);
  private   { Private declarations }
  public    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.vleSetEditText(Sender: TObject; ACol, ARow: Integer; const Value: String);
begin
  memo1.SelText := 'blabla';
//  --stuff---
//  memo1.SetFocus;
end;

procedure TForm1.vleDrawCell(Sender: TObject; ACol, ARow: Integer; Rect: TRect; State: TGridDrawState);
begin
  if vle.Cells[ACol,ARow] = '<color>' then
    vle.Cells[ACol,ARow] := 'COLOR';
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  vle.Cells[1,4] := '<colour>';
  vle.Cells[1,SpinEdit.Value] := '<color>';
end;

procedure TForm1.SpinEditExit(Sender: TObject);
begin
  if (SpinEdit.Text='') then
    SpinEdit.Value := 0;
end;

end.

//........

object Form1: TForm1
  Left = 224
  Top = 128
  BorderIcons = [biSystemMenu, biMinimize]
  BorderStyle = bsSingle
  Caption = 'ValueListEditor'
  ClientHeight = 414
  ClientWidth = 688
  Color = clBtnFace
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -11
  Font.Name = 'MS Sans Serif'
  Font.Style = []
  OldCreateOrder = False
  Position = poDesktopCenter
  PixelsPerInch = 96
  TextHeight = 13
  object vle: TValueListEditor
    Left = 352
    Top = 4
    Width = 320
    Height = 403
    Strings.Strings = (
      '1=11'
      '2=22'
      '3=33'
      '4=44'
      '5=<color>')
    TabOrder = 0
    OnDrawCell = vleDrawCell
    OnSetEditText = vleSetEditText
    ColWidths = (
      150
      164)
  end
  object Memo1: TMemo
    Left = 8
    Top = 32
    Width = 336
    Height = 176
    Lines.Strings = (
      'castledragons blabla')
    TabOrder = 1
    WantTabs = True
  end
  object Memo11: TMemo
    Left = 8
    Top = 216
    Width = 336
    Height = 192
    TabOrder = 2
    WantTabs = True
  end
  object Button1: TButton
    Left = 264
    Top = 5
    Width = 80
    Height = 24
    Caption = '<color>'
    TabOrder = 3
    OnClick = Button1Click
  end
  object SpinEdit: TSpinEdit
    Left = 200
    Top = 5
    Width = 48
    Height = 22
    MaxValue = 5
    MinValue = 1
    TabOrder = 4
    Value = 1
    OnExit = SpinEditExit
  end
end
0
 

Author Comment

by:yehiaeg
ID: 11782358
maybe i'll try LRHGuy , but still have one question to avoid flickering

is there any method in the valuelist editor to repaint or
refresh a particular cell to avoid flickering,
i can repaint the whole control v.repaint or v.refresh or v.invalidate, but
i only need one cell to be redrew,

So, anyway to do this? (other than calling the DrawCell event with my
parameters)


0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
FMX enumerated colours 2 84
How to debug For loops? 3 45
TServerSocket - file via sendbuf or Text via sendtext ? 1 42
Installshield for Embarcadero EX 10.1 Berlin 4 18
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…
Internet Business Fax to Email Made Easy - With  eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, f…

910 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

25 Experts available now in Live!

Get 1:1 Help Now