开发者

Right to left TListView

开发者_如何学C

I am programming a tlistview so that it displays its columns from right to left (so as to properly display Hebrew text). I am using the following code in the form's create method, where 'lv' is the listview

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

 lv.invalidate;   

Whilst this code makes the lines in the listview display correctly, the header line displays from left to right! The columns don't match up and the heading for each column is wrong.

Does anyone have an idea how to get the header line to display right to left?

I am using Delphi 7, not that this should make much difference.

TIA, No'am


Here is the full code to set the header and the 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;


I hope this sample'll 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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜