TDBGrid right align columns and set caret pos when editing value

383 Views Asked by At

I want to set the caret position in my derived TInplaceEdit in a derived DBGrid, similiar to a TDBGrid for right aligned columns.

procedure TMyGridEditor.CreateParams(var Params: TCreateParams);
const
  Alignments : array[TAlignment] of LongWord= (ES_Left, ES_Right, ES_Center);
begin
  inherited CreateParams(Params);
  Params.Style := Params.Style or Alignments[FAlignment];
end;

procedure TMyGridEditor.UpdateContents;
begin
  inherited;
  // if Assigned(Grid) and Assigned(Grid.SelectedColumn) then begin
  //  Alignment := Grid.SelectedColumn.Alignment;
  if (TDBGrid(Grid).SelectedIndex <> -1) then 
    Alignment := TDBGrid(Grid).Columns[TDBGrid(Grid).SelectedIndex].Alignment;
end;

Additional description:

Grid.SelectedColumn = Currently selected column of the grid

Sample picure: Column too small for value

Problem1: The caret position is always on the right and positioned after the last character, this looks strange for ie. string and memo contents. How can I set the caret to the left, just after the inplaceeditor will be displayed.

Problem2: The contents for number values are displayed on multiple lines, when there is not sufficient space avaiable (column is too small). This looks very strange.

How can I accomplish these tasks? Any help appreciated... Thanks

0

There are 0 best solutions below