我在我的表单中使用TListView(继承自TCustomListView),当我将ListView样式更改为"vsSmallIcon"时,图标排列得很糟糕.自从我们将我们的代码从Borland 2006移植到XE4以来,我们发现了这个问题.休息所有"ViewStyle"就像vsIcon,vsList和vsReport一样正常.有没有人遇到与VCL的TlistView组件类似的问题?我已经尝试了ListView1-> Arrange(arDefault)和'AutoArrange'图标选项,但似乎没有任何东西可用于'vsSmallIcon'TViewStyle.
我在Windows 7上使用RAD Studio XE4和Update1.
谢谢,
Santosh Thankachan
PS:添加了一个图像来显示vsSmallIcon TViewStyle的这个问题.

//SmallIconIssue.h
#ifndef SmallIconsIssueH
#define SmallIconsIssueH
#include <System.Classes.hpp>
#include <Vcl.Controls.hpp>
#include <Vcl.StdCtrls.hpp>
#include <Vcl.Forms.hpp>
#include <Vcl.ImgList.hpp>
#include <Vcl.ComCtrls.hpp>
class TSmallIconTest : public TForm
{
__published: // IDE-managed Components
TImageList *ImageList1;
TComboBox *ComboBox1;
TListView *ListView1;
TLabel *Label1;
void __fastcall FormCreate(TObject *Sender);
void __fastcall ComboBox1Click(TObject *Sender);
private: // User declarations
public: // User declarations
__fastcall TSmallIconTest(TComponent* Owner);
};
extern PACKAGE TSmallIconTest *SmallIconTest;
#endif
//SmallIconIssue.cpp
#pragma package(smart_init)
#pragma resource "*.dfm"
TSmallIconTest …Run Code Online (Sandbox Code Playgroud) 我想自动调整TListView中的所有列.我正在使用下面的代码,但它没有做任何事情.
ListView1.Columns.Add.Caption := 'Field Name';
ListView1.Columns.Items[0].Autosize := True;
Run Code Online (Sandbox Code Playgroud)
如何在Delphi中自动调整TListView的列.
我设定了我的ViewStyle to vsReport.
提前致谢
当我使用的TListView(ViewStyle = vsReport)我可以自动调整的列的宽度设置LVSCW_AUTOSIZE或LVSCW_AUTOSIZE_USEHEADER在每一列中的宽度属性值,现在我开始使用在虚拟模式的列表视图,但列的宽度没有被修改根据这些价值观.所以问题是:当lisvtiew处于虚拟模式时,如何调整列的宽度以适应内容或标题?
我使用Delphi 2007.我有一个TListViewwith OwnerData并OwnerDraw设置为True.ViewStyle设置为vsReport.
我有一个record.
type TAList=record
Item:Integer;
SubItem1:String;
SubItem2:String;
end;
var
ModuleData: array of TAList;
procedure TForm1.ListView3Data(Sender: TObject; Item: TListItem);
begin
Item.Caption := IntToStr(ModuleData[Item.Index].Item);
Item.SubItems.Add(ModuleData[Item.Index].SubItem1);
Item.SubItems.Add(ModuleData[Item.Index].SubItem2);
end;
procedure TForm1.ListView3DrawItem(Sender: TCustomListView; Item: TListItem; Rect: TRect; State: TOwnerDrawState);
var
LIndex : integer;
LRect: TRect;
LText: string;
TTListView: TListView;
begin
TTListView := TListView(Sender);
if (Item.SubItems[0] = '...') then
begin
TTListView.Canvas.Brush.Color := clHighlight;
TTListView.Canvas.Font.Color := clHighlightText;
end else
begin
TTListView.Canvas.Brush.Color := TTListView.Color;
TTListView.Canvas.Font.Color …Run Code Online (Sandbox Code Playgroud) 在Delphi XE7中,我使用此技巧根据是否选择了ListView中的项目来自动启用或禁用工具栏按钮("编辑ListView项目"),以防止用户在没有ListView时单击按钮选择的项目:
actTest. actTest给按钮. 在OnUpdate该事件actTest的行动写:
procedure TForm1.actTestUpdate(Sender: TObject);
begin
actTest.Enabled := ListView1.SelCount > 0;
CodeSite.Send('actTestUpdate'); // gets fired very often!
end;
Run Code Online (Sandbox Code Playgroud)现在,您可以看到根据是否选择了ListView中的项目来启用或禁用该按钮,与您是使用鼠标还是使用键盘或以编程方式选择/取消选择项目无关.
但是,在CodeSite Live Viewer中,我可以看到actTestUpdate事件是连续且非常频繁地触发的,因此该语句很快actTest.Enabled := ListView1.SelCount > 0;就被执行了.
所以我的问题是:这会降低性能吗?如果是,是否有另一种技巧可以实现上述目的?
如何对tlistview存在的数据进行排序subitem[x]?
我在vsreport虚拟模式下使用listview,有两列,在我填充列表后,选择一行,然后选择其他行,在先前选定的行上留下一个工件,请参见下图.如何解决这个问题?
这是我从数组中获取数据的代码
procedure TForm1.ListView1Data(Sender: TObject; Item: TListItem);
begin
Item.Caption := FloatToStr(Item.Index + 1);
Item.SubItems.Add(FloatToStr(a[Item.Index]));
end;
Run Code Online (Sandbox Code Playgroud)
当我将鼠标悬停时,文物会消失.谢谢
我需要在a中的特定列中绘制一个复选框TListView,所以我检查这个问题How can I setup TListView with CheckBoxes in only certain columns?并在接受的答案中建议使用另一个问题中描述的方法How to set a Checkbox TStringGrid in Delphi?,现在移植该代码以使用ListView我带有这个:
procedure TForm15.ListView1CustomDrawSubItem(Sender: TCustomListView; Item: TListItem; SubItem: Integer; State: TCustomDrawState; var DefaultDraw: Boolean);
const
PADDING = 4;
var
h : HTHEME;
s : TSize;
r : TRect;
Rect : TRect;
i : Integer;
Dx : Integer;
begin
if (SubItem=1) then
begin
DefaultDraw:=True;
Rect :=Item.DisplayRect(drBounds);
Dx:=0;
for i := 0 to SubItem do
Inc(Dx,Sender.Column[i].Width);
Rect.Left :=Rect.Left+Dx;
Rect.Right :=Rect.Left+Sender.Column[SubItem+1].Width; …Run Code Online (Sandbox Code Playgroud) 这似乎是一个愚蠢而简单的问题,然而,我一直无法找到令人满意的答案.基本上,我有一个带数据的TListview(style = vsReport).有时,我必须更新它,因此,我必须清除列表视图并使用更新的数据再次填充它.
但是,当我这样做时,滚动条位置重置为0.我希望能够在清除之前获得滚动条位置并将其设置回原来的状态.如果更新的数据与旧数据具有完全相同的行数,我需要滚动条与之前的位置完全相同; 如果没有,我只需要它和以前在同一个地方或多或少.
看起来很简单吧?然而,我发现的只有TopItem和MakeVisible的黑客或调整.有没有适当的方法来做到这一点?
谢谢!
我需要启用或禁用按钮,具体取决于列表中是否至少选择了一行.
以下是重现此问题的代码.使用OnData事件填充列表,它允许选择多行.
我以为我可以使用OnSelectItem来检测用户何时更改选择,然后使用TListView SelCount函数来检测所选行的数量.
问题是当用户选择多行时,SelCount返回0.如果手动填充列表(即不通过OnData事件),这可以正常工作.
有任何想法吗?
谢谢
更新:使用OnChange事件似乎可以解决问题.仍然有趣的是,当选择多行时(从SelectItem事件中),SelCount为什么返回0.
另一个更新:我发布了一个测试项目:https://dl.dropboxusercontent.com/u/35370420/TestListView2.zip以及截图:
要重现此问题,请运行应用程序,选择Item1,然后按SHIFT +单击Item2.该按钮被禁用.我的目的是只要在列表中选择了至少一个项目,就动态启用按钮.如果没有选定项目,则禁用该按钮.
PAS文件:
unit MainUnit;
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.ComCtrls, Vcl.StdCtrls;
type
TForm3 = class(TForm)
ListView1: TListView;
Button1: TButton;
procedure FormCreate(Sender: TObject);
procedure ListView1Data(Sender: TObject; Item: TListItem);
procedure ListView1SelectItem(Sender: TObject; Item: TListItem; Selected: Boolean);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form3: TForm3;
implementation
{$R *.dfm}
procedure TForm3.FormCreate(Sender: TObject);
begin
ListView1.Items.Count := 5;
end;
procedure …Run Code Online (Sandbox Code Playgroud) delphi ×10
tlistview ×10
delphi-xe ×2
vcl ×2
checkbox ×1
delphi-2006 ×1
delphi-2007 ×1
delphi-xe2 ×1
delphi-xe4 ×1
delphi-xe5 ×1
delphi-xe7 ×1
hint ×1
icons ×1
listview ×1
ownerdrawn ×1
scrollbar ×1
taction ×1