2)怎样实现点击标题行排序的功能?请给出具体代码!
多谢!
12 个解决方案
#1
1)改变高度很简单,自己试试就知道。
2)点击标题排序用TCustomListView.CustomSort,看看帮助吧。
具体代码:
procedure TfrmCenter.lvCenterColumnClick(Sender: TObject;
Column: TListColumn); //lvCenter---Tlistview;
begin
if lvCenter.Items.Count = 0 then Exit;
intSortColumn := Column.Index;
if blvCenter[intSortColumn] then lvCenter.CustomSort(@CustomSortDescProc, 0)
else lvCenter.CustomSort(@CustomSortAscProc, 0);//asc-正序
blvCenter[intSortColumn] := not blvCenter[intSortColumn];
end;
function CustomSortAscProc(Item1, Item2: TListItem; ParamSort: integer): integer; stdcall;
begin
if intSortColumn = 0 then
Result := CompareText(Item1.Caption, Item2.Caption)
else if intSortColumn > 0 then
Result := CompareText(Item1.SubItems[intSortColumn - 1], Item2.SubItems[intSortColumn - 1]);
end;
function CustomSortDescProc(Item1, Item2: TListItem; ParamSort: integer): integer; stdcall;
begin
if intSortColumn = 0 then
Result := - CompareText(Item1.Caption, Item2.Caption)
else if intSortColumn > 0 then
Result := - CompareText(Item1.SubItems[intSortColumn - 1], Item2.SubItems[intSortColumn - 1]);
end;
2)点击标题排序用TCustomListView.CustomSort,看看帮助吧。
具体代码:
procedure TfrmCenter.lvCenterColumnClick(Sender: TObject;
Column: TListColumn); //lvCenter---Tlistview;
begin
if lvCenter.Items.Count = 0 then Exit;
intSortColumn := Column.Index;
if blvCenter[intSortColumn] then lvCenter.CustomSort(@CustomSortDescProc, 0)
else lvCenter.CustomSort(@CustomSortAscProc, 0);//asc-正序
blvCenter[intSortColumn] := not blvCenter[intSortColumn];
end;
function CustomSortAscProc(Item1, Item2: TListItem; ParamSort: integer): integer; stdcall;
begin
if intSortColumn = 0 then
Result := CompareText(Item1.Caption, Item2.Caption)
else if intSortColumn > 0 then
Result := CompareText(Item1.SubItems[intSortColumn - 1], Item2.SubItems[intSortColumn - 1]);
end;
function CustomSortDescProc(Item1, Item2: TListItem; ParamSort: integer): integer; stdcall;
begin
if intSortColumn = 0 then
Result := - CompareText(Item1.Caption, Item2.Caption)
else if intSortColumn > 0 then
Result := - CompareText(Item1.SubItems[intSortColumn - 1], Item2.SubItems[intSortColumn - 1]);
end;
#2
1、向listview发送消息LVM_SETCOLUMNWIDTH
2、自己在OnColumnClick事件里面写排序代码
2、自己在OnColumnClick事件里面写排序代码
#3
sorry,说错了,不是这个消息
#4
我试过了,还是不能改变高度!
#5
为甚么要改高度?说来听听?列表要显示的是什么?
#6
默认高度显示出来不美观!
#7
有个折中的办法,改字体就行了。
#8
这个程序也许对你的第一个问题有帮助!
procedure TFrmMain.LV1AdvancedCustomDrawItem(Sender: TCustomListView;
Item: TListItem; State: TCustomDrawState; Stage: TCustomDrawStage;
var DefaultDraw: Boolean);
begin
if item.Index mod 2 = 1 then
sender.Canvas.Brush.Color:=clskyblue
else
sender.bCanvas.Brush.Color:=clmoneygreen;
end;
procedure TFrmMain.LV1AdvancedCustomDrawItem(Sender: TCustomListView;
Item: TListItem; State: TCustomDrawState; Stage: TCustomDrawStage;
var DefaultDraw: Boolean);
begin
if item.Index mod 2 = 1 then
sender.Canvas.Brush.Color:=clskyblue
else
sender.bCanvas.Brush.Color:=clmoneygreen;
end;
#9
码BOY:
改变字体解决不了问题,因为每一行文字还是紧贴着上下边框!
改变字体解决不了问题,因为每一行文字还是紧贴着上下边框!
#10
第一个问题依然没有解决!
#11
我的方法是,全部的东西自己重画:
procedure TForm1.ListView1AdvancedCustomDrawItem(Sender: TCustomListView;
Item: TListItem; State: TCustomDrawState; Stage: TCustomDrawStage;
var DefaultDraw: Boolean);
begin
//DefaultDraw := False;
Sender.Canvas.Rectangle(Item.DisplayRect(drLabel));
end;
procedure TForm1.ListView1AdvancedCustomDrawItem(Sender: TCustomListView;
Item: TListItem; State: TCustomDrawState; Stage: TCustomDrawStage;
var DefaultDraw: Boolean);
begin
//DefaultDraw := False;
Sender.Canvas.Rectangle(Item.DisplayRect(drLabel));
end;
#12
将其和一ImageList关联,然后设置ImageList!
#1
1)改变高度很简单,自己试试就知道。
2)点击标题排序用TCustomListView.CustomSort,看看帮助吧。
具体代码:
procedure TfrmCenter.lvCenterColumnClick(Sender: TObject;
Column: TListColumn); //lvCenter---Tlistview;
begin
if lvCenter.Items.Count = 0 then Exit;
intSortColumn := Column.Index;
if blvCenter[intSortColumn] then lvCenter.CustomSort(@CustomSortDescProc, 0)
else lvCenter.CustomSort(@CustomSortAscProc, 0);//asc-正序
blvCenter[intSortColumn] := not blvCenter[intSortColumn];
end;
function CustomSortAscProc(Item1, Item2: TListItem; ParamSort: integer): integer; stdcall;
begin
if intSortColumn = 0 then
Result := CompareText(Item1.Caption, Item2.Caption)
else if intSortColumn > 0 then
Result := CompareText(Item1.SubItems[intSortColumn - 1], Item2.SubItems[intSortColumn - 1]);
end;
function CustomSortDescProc(Item1, Item2: TListItem; ParamSort: integer): integer; stdcall;
begin
if intSortColumn = 0 then
Result := - CompareText(Item1.Caption, Item2.Caption)
else if intSortColumn > 0 then
Result := - CompareText(Item1.SubItems[intSortColumn - 1], Item2.SubItems[intSortColumn - 1]);
end;
2)点击标题排序用TCustomListView.CustomSort,看看帮助吧。
具体代码:
procedure TfrmCenter.lvCenterColumnClick(Sender: TObject;
Column: TListColumn); //lvCenter---Tlistview;
begin
if lvCenter.Items.Count = 0 then Exit;
intSortColumn := Column.Index;
if blvCenter[intSortColumn] then lvCenter.CustomSort(@CustomSortDescProc, 0)
else lvCenter.CustomSort(@CustomSortAscProc, 0);//asc-正序
blvCenter[intSortColumn] := not blvCenter[intSortColumn];
end;
function CustomSortAscProc(Item1, Item2: TListItem; ParamSort: integer): integer; stdcall;
begin
if intSortColumn = 0 then
Result := CompareText(Item1.Caption, Item2.Caption)
else if intSortColumn > 0 then
Result := CompareText(Item1.SubItems[intSortColumn - 1], Item2.SubItems[intSortColumn - 1]);
end;
function CustomSortDescProc(Item1, Item2: TListItem; ParamSort: integer): integer; stdcall;
begin
if intSortColumn = 0 then
Result := - CompareText(Item1.Caption, Item2.Caption)
else if intSortColumn > 0 then
Result := - CompareText(Item1.SubItems[intSortColumn - 1], Item2.SubItems[intSortColumn - 1]);
end;
#2
1、向listview发送消息LVM_SETCOLUMNWIDTH
2、自己在OnColumnClick事件里面写排序代码
2、自己在OnColumnClick事件里面写排序代码
#3
sorry,说错了,不是这个消息
#4
我试过了,还是不能改变高度!
#5
为甚么要改高度?说来听听?列表要显示的是什么?
#6
默认高度显示出来不美观!
#7
有个折中的办法,改字体就行了。
#8
这个程序也许对你的第一个问题有帮助!
procedure TFrmMain.LV1AdvancedCustomDrawItem(Sender: TCustomListView;
Item: TListItem; State: TCustomDrawState; Stage: TCustomDrawStage;
var DefaultDraw: Boolean);
begin
if item.Index mod 2 = 1 then
sender.Canvas.Brush.Color:=clskyblue
else
sender.bCanvas.Brush.Color:=clmoneygreen;
end;
procedure TFrmMain.LV1AdvancedCustomDrawItem(Sender: TCustomListView;
Item: TListItem; State: TCustomDrawState; Stage: TCustomDrawStage;
var DefaultDraw: Boolean);
begin
if item.Index mod 2 = 1 then
sender.Canvas.Brush.Color:=clskyblue
else
sender.bCanvas.Brush.Color:=clmoneygreen;
end;
#9
码BOY:
改变字体解决不了问题,因为每一行文字还是紧贴着上下边框!
改变字体解决不了问题,因为每一行文字还是紧贴着上下边框!
#10
第一个问题依然没有解决!
#11
我的方法是,全部的东西自己重画:
procedure TForm1.ListView1AdvancedCustomDrawItem(Sender: TCustomListView;
Item: TListItem; State: TCustomDrawState; Stage: TCustomDrawStage;
var DefaultDraw: Boolean);
begin
//DefaultDraw := False;
Sender.Canvas.Rectangle(Item.DisplayRect(drLabel));
end;
procedure TForm1.ListView1AdvancedCustomDrawItem(Sender: TCustomListView;
Item: TListItem; State: TCustomDrawState; Stage: TCustomDrawStage;
var DefaultDraw: Boolean);
begin
//DefaultDraw := False;
Sender.Canvas.Rectangle(Item.DisplayRect(drLabel));
end;
#12
将其和一ImageList关联,然后设置ImageList!