How to set text in selected cell

I have a fowm with a TAdvStringGrid component. Column 0 of the grid contains a nonsequential group of integers and column 1 contains a string, which may be empty or one word. Column 1 has an edComboList inplace editor that includes the allowable values. I'm trying to set the values in column 1 in a routine.

The code below works, except on the currently selected cell. The text value in that cell remains unchanged. I suspect it has to do with the fact that there is an editor for that column, but I can't figure out how to either disable the editor before doing the update, or even determine which is the currently selected cell in code.

    int MyForm::SetAC(String & Flt, String & AC) {
       TFindParams fp = TFindParams();
       fp << fnFindInPresetCol << fnMatchFull;
       // sgFlights is the name of the TAdvStringGrid
       TPoint p = sgFlights->Find(TPoint(0, 0), Flt, fp);
       if (p.y > 0) {
          sgFlights->Cells[1][p.y] = AC;
    
       }
       return p.y;
    }
    void MyForm::LoadFACfromGDB() {
         std::map<int, String>FlightMatcher;
         // .. code to populate flight matcher...
          map<int, String>::const_iterator itr;
          for (itr = FlightMatcher.begin(); itr != FlightMatcher.end(); ++itr) {
             String Flt = IntToStr(itr->first);
             String AC = itr->second;
             SetAC(Flt, AC);
    }

These are the properties of sgFlights from the dfm file:
  object sgFlights: TAdvStringGrid
    Left = 22
    Top = 128
    Width = 225
    Height = 192
    Cursor = crDefault
    Hint = 'Flights on the left, aircraft on the right'
    Anchors = [akLeft, akTop, akRight, akBottom]
    ColCount = 2
    DrawingStyle = gdsClassic
    Font.Charset = DEFAULT_CHARSET
    Font.Color = clWindowText
    Font.Height = -11
    Font.Name = 'Tahoma'
    Font.Style = []
    Options = [goFixedVertLine, goFixedHorzLine, goVertLine, goHorzLine, goRangeSelect, goEditing]
    ParentFont = False
    ScrollBars = ssBoth
    TabOrder = 0
    OnExit = sgFlightsExit
    OnMouseLeave = sgFlightsMouseLeave
    HoverRowCells = [hcNormal, hcSelected]
    OnGetEditorType = sgFlightsGetEditorType
    OnGetEditorProp = sgFlightsGetEditorProp
    ActiveCellFont.Charset = DEFAULT_CHARSET
    ActiveCellFont.Color = clWindowText
    ActiveCellFont.Height = -11
    ActiveCellFont.Name = 'Tahoma'
    ActiveCellFont.Style = [fsBold]
    ColumnHeaders.Strings = (
      'Flight'
      'Aircraft')
    ControlLook.FixedGradientHoverFrom = 15000287
    ControlLook.FixedGradientHoverTo = 14406605
    ControlLook.FixedGradientHoverMirrorFrom = 14406605
    ControlLook.FixedGradientHoverMirrorTo = 13813180
    ControlLook.FixedGradientHoverBorder = 12033927
    ControlLook.FixedGradientDownFrom = 14991773
    ControlLook.FixedGradientDownTo = 14991773
    ControlLook.FixedGradientDownMirrorFrom = 14991773
    ControlLook.FixedGradientDownMirrorTo = 14991773
    ControlLook.FixedGradientDownBorder = 14991773
    ControlLook.DropDownHeader.Font.Charset = DEFAULT_CHARSET
    ControlLook.DropDownHeader.Font.Color = clWindowText
    ControlLook.DropDownHeader.Font.Height = -11
    ControlLook.DropDownHeader.Font.Name = 'Tahoma'
    ControlLook.DropDownHeader.Font.Style = []
    ControlLook.DropDownHeader.Visible = True
    ControlLook.DropDownHeader.Buttons = <>
    ControlLook.DropDownFooter.Font.Charset = DEFAULT_CHARSET
    ControlLook.DropDownFooter.Font.Color = clWindowText
    ControlLook.DropDownFooter.Font.Height = -11
    ControlLook.DropDownFooter.Font.Name = 'Tahoma'
    ControlLook.DropDownFooter.Font.Style = []
    ControlLook.DropDownFooter.Visible = True
    ControlLook.DropDownFooter.Buttons = <>
    EnhRowColMove = False
    Filter = <>
    FilterDropDown.Font.Charset = DEFAULT_CHARSET
    FilterDropDown.Font.Color = clWindowText
    FilterDropDown.Font.Height = -11
    FilterDropDown.Font.Name = 'Tahoma'
    FilterDropDown.Font.Style = []
    FilterDropDown.TextChecked = 'Checked'
    FilterDropDown.TextUnChecked = 'Unchecked'
    FilterDropDownClear = '(All)'
    FilterEdit.TypeNames.Strings = (
      'Starts with'
      'Ends with'
      'Contains'
      'Not contains'
      'Equal'
      'Not equal'
      'Clear')
    FixedRowHeight = 22
    FixedFont.Charset = DEFAULT_CHARSET
    FixedFont.Color = clWindowText
    FixedFont.Height = -11
    FixedFont.Name = 'Tahoma'
    FixedFont.Style = [fsBold]
    FloatFormat = '%.2f'
    Look = glStandard
    Lookup = True
    LookupHistory = True
    MouseActions.DirectComboClose = True
    MouseActions.DirectComboDrop = True
    MouseActions.DirectEdit = True
    Navigation.AdvanceOnEnter = True
    Navigation.AdvanceOnEnterLoop = False
    Navigation.AdvanceDirection = adTopBottom
    Navigation.AllowCtrlEnter = False
    Navigation.AdvanceAuto = True
    Navigation.CursorWalkEditor = True
    PrintSettings.DateFormat = 'dd/mm/yyyy'
    PrintSettings.Font.Charset = DEFAULT_CHARSET
    PrintSettings.Font.Color = clWindowText
    PrintSettings.Font.Height = -11
    PrintSettings.Font.Name = 'Tahoma'
    PrintSettings.Font.Style = []
    PrintSettings.FixedFont.Charset = DEFAULT_CHARSET
    PrintSettings.FixedFont.Color = clWindowText
    PrintSettings.FixedFont.Height = -11
    PrintSettings.FixedFont.Name = 'Tahoma'
    PrintSettings.FixedFont.Style = []
    PrintSettings.HeaderFont.Charset = DEFAULT_CHARSET
    PrintSettings.HeaderFont.Color = clWindowText
    PrintSettings.HeaderFont.Height = -11
    PrintSettings.HeaderFont.Name = 'Tahoma'
    PrintSettings.HeaderFont.Style = []
    PrintSettings.FooterFont.Charset = DEFAULT_CHARSET
    PrintSettings.FooterFont.Color = clWindowText
    PrintSettings.FooterFont.Height = -11
    PrintSettings.FooterFont.Name = 'Tahoma'
    PrintSettings.FooterFont.Style = []
    PrintSettings.PageNumSep = '/'
    SearchFooter.Color = clBtnFace
    SearchFooter.FindNextCaption = 'Find &next'
    SearchFooter.FindPrevCaption = 'Find &previous'
    SearchFooter.Font.Charset = DEFAULT_CHARSET
    SearchFooter.Font.Color = clWindowText
    SearchFooter.Font.Height = -11
    SearchFooter.Font.Name = 'Tahoma'
    SearchFooter.Font.Style = []
    SearchFooter.HighLightCaption = 'Highlight'
    SearchFooter.HintClose = 'Close'
    SearchFooter.HintFindNext = 'Find next occurrence'
    SearchFooter.HintFindPrev = 'Find previous occurrence'
    SearchFooter.HintHighlight = 'Highlight occurrences'
    SearchFooter.MatchCaseCaption = 'Match case'
    SelectionColor = clHighlight
    SelectionTextColor = clHighlightText
    Version = '7.0.4.0'
    WordWrap = False
    ColWidths = (
      64
      204)
    RowHeights = (
      22
      22
      22
      22
      22
      22
      22
      22
      22
      22)
  end



cheers,

Marc

You mean there is always an editor active for the selected cell?
If so, you'll need to set the value in the inplace editor. If this is the default inplace editor, you'd do this via

grid.NormalEdit.Text := 'newvalue';

Hello Bruno,


No the editor isn't always active, its just that there's always a cell that is selected, and I don't seem to be able to enter text there.

I tried testing for the Selection TGridRect and if I was in it I used NormalEdit, but that threw an exception.

I've fixed it finally by removing the selection altogether like this:
   TGridRect gr = sgFlights->Selection;
   gr.Top = 0;
   gr.Bottom = 0;
   sgFlights->Selection = gr;
I have 1 fixed row and 1 fixed column, so that essentially removes the selection. I also tried ClearSelection, but strangely that's not what it does.

cheers,

Marc

I cannot reproduce any issue here with updating the content of just the selected cell.
For example, with a default grid, cell 1,1 is the selected cell but updating it with:

grid.Cells[1,1] := 'test';
works fine.
Please provide exact & detailed information with which we can understand/reproduce this problem here.