Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

PickList and ValueListEditor

Posted on 2004-08-10
8
Medium Priority
?
3,225 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 12

Expert Comment

by:esoftbg
ID: 11772955
> sell
cell
0
 
LVL 7

Accepted Solution

by:
LRHGuy earned 375 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

Ask an Anonymous Question!

Don't feel intimidated by what you don't know. Ask your question anonymously. It's easy! Learn more and upgrade.

Question has a verified solution.

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

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses

609 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