Jump to content


Reading a Value from a ComboBoxColumn or List Column.


  • Please log in to reply
3 replies to this topic

#1 Speed

Speed
  • Members
  • 23 posts

Posted 28 June 2012 - 03:20 AM

I want to be able to read a value that a user has just selected in a ComboBoxColumn or a ListColumn.  I have tried using the following code for a ListColumn in a number of different events(OnCloseUp, onselect, OnAfterEdit, onchange, etc.), but I only get the previous value, not the new value:

var
  SelectedText: string;
begin
  SelectedText := colUserStatus.Items[grdUsers.Cell[1, grdUsers.SelectedRow].AsInteger];

  CodeSite.Send('SelectedText', SelectedText);
end;


Thanks.

#2 Speed

Speed
  • Members
  • 23 posts

Posted 28 June 2012 - 03:28 AM

Is this the correct way:

procedure TfrmMain.colUserStatusCloseUp(Sender: TObject);
var
    SelectedText: string;
begin
SelectedText := colUserStatus.Editor.AsString;

CodeSite.Send('SelectedText', SelectedText);
end;

#3 deonvn

deonvn

    Senior Member

  • Honorable Members
  • PipPip
  • 303 posts

Posted 28 June 2012 - 09:54 AM

Hi

You can also use the column's OnCloseUp event provided that you call ApplyEditing first:

procedure TForm1.NxComboBoxColumn1CloseUp(Sender: TObject);
begin
  NextGrid1.ApplyEditing;
  ShowMessage(NextGrid1.Cell[NextGrid1.SelectedColumn,NextGrid1.SelectedRow].AsString);
end;

This will work for ComboBoxColumn and ListColumn, but note that for a ListColumn the value that is returned is the underlying index of the selected item - not the actual text in the cell.

#4 Speed

Speed
  • Members
  • 23 posts

Posted 29 June 2012 - 01:03 AM

I

View Postdeonvn, on 28 June 2012 - 09:54 AM, said:

Hi

You can also use the column's OnCloseUp event provided that you call ApplyEditing first:

procedure TForm1.NxComboBoxColumn1CloseUp(Sender: TObject);
begin
  NextGrid1.ApplyEditing;
  ShowMessage(NextGrid1.Cell[NextGrid1.SelectedColumn,NextGrid1.SelectedRow].AsString);
end;

This will work for ComboBoxColumn and ListColumn, but note that for a ListColumn the value that is returned is the underlying index of the selected item - not the actual text in the cell.

I didn't know about ApplyEditing - thanks for that.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users