Recent

Author Topic: Add a value in TValuelistbox  (Read 3511 times)

KMagic

  • Full Member
  • ***
  • Posts: 100
Add a value in TValuelistbox
« on: March 31, 2014, 07:49:49 pm »
Hi everyone, I have a ValueListEditor1 and want to add some values in it. However, I can only add values in column Name by using String properties.  I don't know how to add values in column Key. Could anyone show me how to do it?

http://postimg.org/image/7bx1obrlb/

howardpc

  • Hero Member
  • *****
  • Posts: 4144
Re: Add a value in TValuelistbox
« Reply #1 on: March 31, 2014, 10:09:00 pm »
The TStringList class has built-in support for key/value string pairs in the format
   key=value.

The TValuelistEditor is a customised 2-column stringgrid that enables users to edit such strings easily.
Typing
Code: [Select]
uk=United Kingdom
us=United States of America
fr=France
de=Germany
ru=Russia
nl=Holland
in the Strings Editor dialog of TValueListEditor will populate the component so at runtime it appears as in the attached figure.

Bart

  • Hero Member
  • *****
  • Posts: 5575
    • Bart en Mariska's Webstek
Re: Add a value in TValuelistbox
« Reply #2 on: March 31, 2014, 10:46:56 pm »
There is InsertRowWithValues().
Or Strings.Add('AKey=AValue');

Bart

JuhaManninen

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4599
  • I like bugs.
Re: Add a value in TValuelistbox
« Reply #3 on: April 01, 2014, 02:39:12 am »
I added a draft implementation of a property editor for ValueListEditor Strings. It uses ValueListEditor itself for the task. It already works somehow.
See r44574 - r44576.
This is somehow related to the already solved issue: http://bugs.freepascal.org/view.php?id=25881

Maybe Bart could look at this. AutoAddRows feature works somehow but I found a new bug there. When cursor is in the last Value-column and you press arrow down, a new row is added but it also throws an "index out of bounds" error.
When cursor is in the last Key-column, then it works OK.
« Last Edit: April 01, 2014, 02:41:37 am by JuhaManninen »
Mostly Lazarus trunk and FPC 3.2 on Manjaro Linux 64-bit.

KMagic

  • Full Member
  • ***
  • Posts: 100
Re: Add a value in TValuelistbox
« Reply #4 on: April 01, 2014, 07:38:53 am »
Thanks everyone.
@howardpc, I tried your suggestion and it works for me, thank you.

 

TinyPortal © 2005-2018