Right to left TListView

I am programming tlistview to display its columns from right to left (to correctly display Hebrew text). I use the following code in the create method of the form, where 'lv' is a listview

 SetWindowLong (lv.Handle, GWL_EXSTYLE,
                GetWindowLong(lv.Handle, GWL_EXSTYLE)  or
                WS_EX_LAYOUTRTL or WS_EX_NOINHERITLAYOUT);

 lv.invalidate;   

As long as this code displays the lines in the list correctly, the title bar displays from left to right! The columns do not match and the header for each column is incorrect.

Does anyone have an idea how to display the title bar from right to left?

I am using Delphi 7, and not that it should make a big difference.

TIA, No'am

+3
source share
2 answers

Here is the complete code for setting the header and lines:

procedure TForm1.FormCreate(Sender: TObject);
const
  LVM_FIRST = $1000;      // ListView messages
  LVM_GETHEADER = LVM_FIRST + 31;
var
  header: thandle;
begin
  header:= SendMessage (lv.Handle, LVM_GETHEADER, 0, 0);
  SetWindowLong (header, GWL_EXSTYLE,
                 GetWindowLong (header, GWL_EXSTYLE)  or
                 WS_EX_LAYOUTRTL or WS_EX_NOINHERITLAYOUT);

  SetWindowLong (lv.Handle, GWL_EXSTYLE,
                 GetWindowLong (lv.Handle, GWL_EXSTYLE)  or
                 WS_EX_LAYOUTRTL or WS_EX_NOINHERITLAYOUT);
  lv.invalidate;   // get the list view to display right to left
end;
+5
source

I hope this sample will be useful for you:

var
  aCol: TListColumn;
  tmp: TListView;
  i: integer;
begin
  tmp := TListView.Create(Self);
  LV.Columns.BeginUpdate;
  try
    for i := LV.Columns.Count-1 downto 0 do
    begin
      aCol := tmp.Columns.Add;
      aCol.Width := LV.Columns[i].Width;
      aCol.Caption := LV.Columns[i].Caption;
    end;
    LV.Columns := tmp.Columns;
  finally
    LV.Columns.EndUpdate;
    tmp.Free;
  end;
end;
0
source

Source: https://habr.com/ru/post/1720163/


All Articles