delphivcltcxgrid

How to access selected item in TcxEditRepositoryComboBoxItem when looping cxGrid?


I have a save button on my form which loops through all rows of the tcxgrid and reads its values. I'm trying to read the value of a combo box I have in one of the columns, but I need to read the Key value not the text of it.

for I := 0 to tv.DataController.RecordCount - 1 do
begin
  Location := tv.DataController.Values[I, colLocation.Index];
end;

colLocation is the combobox, but doing that gives me the text selected not the ItemIndex values. Any clues?

thanks


Solution

  • If you are asking how to get the numeric index in the ComboBox Items property of the current grid row, you can do it with code like this

    procedure TForm1.ProcessComboBox;
    var
      I,
      Index : Integer;
      S : String;
      V : OleVariant;
    begin
      for I := 0 to tv.DataController.RecordCount - 1 do
      begin
        V := tv.DataController.Values[I, colLocation.Index];
        S := V;
        //  if the RepositoryItem of colLocation is set to cxEditRepository1ComboBoxItem1
        //  you can do
        Index := cxEditRepository1ComboBoxItem1.Properties.Items.IndexOf(S);
    
        //  OR, if the Properties property of colLocation is set to ComboBox you could do
        //  Index := TcxComboBoxProperties(colLocation.Properties).Items.IndexOf(S);
    
        S := IntToStr(Index);
        Caption := S;
      end;
    end;
    

    If that doesn't answer your q, you'd better explain exactly what you do want.