Recent

Author Topic: DBGrid picklist, get selected picklist value.  (Read 574 times)

Hansvb

  • Hero Member
  • *****
  • Posts: 901
DBGrid picklist, get selected picklist value.
« on: May 25, 2025, 09:28:04 pm »
Hi,
I have a dbgrid of which 1 column has a picklist. The picklist is created by assigning a TStringlist to the dbgrid.column.picklist. Now when I select a value from the picklist, I want to pick up this value. But I can't find a PickList.text or anything like that anywhere. I do see
Code: Pascal  [Select][+][-]
  1. DBGrid.Columns[FColIndex]. PickList.ValueFromIndex[i];
Then you get the text, but then you have to know the index. You can also ask for the index:
Code: Pascal  [Select][+][-]
  1.  DBGrid.Columns[FColIndex]. PickList.IndexOf('some text');
but then you need the text first.

I suffer from the chicken - egg story.
How can I read the text of the value selected in the picklist? I need this before it gets into the cell of the dbgrid.

jamie

  • Hero Member
  • *****
  • Posts: 7660
Re: DBGrid picklist, get selected picklist value.
« Reply #1 on: May 25, 2025, 10:07:05 pm »
ItemIndex ?

That is the selected Item, if its -1 then nothing is selected but this is strictly a TstringList, not sure if the DB code gets control of this.
 
 You also have "Items" which is an indexable array of the items.

Jamie
The only true wisdom is knowing you know nothing

Hansvb

  • Hero Member
  • *****
  • Posts: 901
Re: DBGrid picklist, get selected picklist value.
« Reply #2 on: May 26, 2025, 05:17:27 pm »
A picklist is a TStrings I see now and has no ItemIndex. I should probably switch to a dblookup combobox. And let's see what can be done then.

CharlyTango

  • Full Member
  • ***
  • Posts: 178
Re: DBGrid picklist, get selected picklist value.
« Reply #3 on: May 27, 2025, 12:19:17 pm »
It may help if you tell us what you need the value from the picklist for and in what form.

Actually, the value from the picklist should end up in the dataset of the DBGrid and can be accessed there because the record pointer of the dataset is synchronized with the DBGrid via the datasource. Therefore, the dataset pointer of the dataset is already on the correct line and no further identification is necessary.

Code: Pascal  [Select][+][-]
  1. <Datasetname>.Fieldbyname('...').AsString
Lazarus stable, Win32/64

 

TinyPortal © 2005-2018