Solved

PickList and ValueListEditor

Posted on 2004-08-10
8
3,078 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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
This video discusses moving either the default database or any database to a new volume.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

707 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

13 Experts available now in Live!

Get 1:1 Help Now