- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一个包含 3 列的 ListView,想要编辑第三列,即 Subitem[1]。如果我将 ListView.ReadOnly 设置为 False,它允许我编辑所选项目的标题。有没有一种简单的方法可以为子项目做同样的事情?我不想在顶部添加一个进行编辑的无边框控件。
最佳答案
您可以使用 TEdit、自定义消息并处理 ListView 的 OnClick
事件来编辑 ListView 的子项(在报告模式下)。
尝试这个示例
Const
USER_EDITLISTVIEW = WM_USER + 666;
type
TForm1 = class(TForm)
ListView1: TListView;
procedure FormCreate(Sender: TObject);
procedure ListView1Click(Sender: TObject);
private
ListViewEditor: TEdit;
LItem: TListitem;
procedure UserEditListView( Var Message: TMessage ); message USER_EDITLISTVIEW;
procedure ListViewEditorExit(Sender: TObject);
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
uses
CommCtrl;
const
EDIT_COLUMN = 2; //Index of the column to Edit
procedure TForm1.FormCreate(Sender: TObject);
Var
I : Integer;
Item : TListItem;
begin
for I := 0 to 9 do
begin
Item:=ListView1.Items.Add;
Item.Caption:=Format('%d.%d',[i,1]);
Item.SubItems.Add(Format('%d.%d',[i,2]));
Item.SubItems.Add(Format('%d.%d',[i,3]));
end;
//create the TEdit and assign the OnExit event
ListViewEditor:=TEdit.Create(Self);
ListViewEditor.Parent:=ListView1;
ListViewEditor.OnExit:=ListViewEditorExit;
ListViewEditor.Visible:=False;
end;
procedure TForm1.ListView1Click(Sender: TObject);
var
LPoint: TPoint;
LVHitTestInfo: TLVHitTestInfo;
begin
LPoint:= listview1.ScreenToClient(Mouse.CursorPos);
ZeroMemory( @LVHitTestInfo, SizeOf(LVHitTestInfo));
LVHitTestInfo.pt := LPoint;
//Check if the click was made in the column to edit
If (ListView1.perform( LVM_SUBITEMHITTEST, 0, LPARAM(@LVHitTestInfo))<>-1) and ( LVHitTestInfo.iSubItem = EDIT_COLUMN ) Then
PostMessage( self.Handle, USER_EDITLISTVIEW, LVHitTestInfo.iItem, 0 )
else
ListViewEditor.Visible:=False; //hide the TEdit
end;
procedure TForm1.ListViewEditorExit(Sender: TObject);
begin
If Assigned(LItem) Then
Begin
//assign the vslue of the TEdit to the Subitem
LItem.SubItems[ EDIT_COLUMN-1 ] := ListViewEditor.Text;
LItem := nil;
End;
end;
procedure TForm1.UserEditListView(var Message: TMessage);
var
LRect: TRect;
begin
LRect.Top := EDIT_COLUMN;
LRect.Left:= LVIR_BOUNDS;
listview1.Perform( LVM_GETSUBITEMRECT, Message.wparam, LPARAM(@LRect) );
MapWindowPoints( listview1.Handle, ListViewEditor.Parent.Handle, LRect, 2 );
//get the current Item to edit
LItem := listview1.Items[ Message.wparam ];
//set the text of the Edit
ListViewEditor.Text := LItem.Subitems[ EDIT_COLUMN-1];
//set the bounds of the TEdit
ListViewEditor.BoundsRect := LRect;
//Show the TEdit
ListViewEditor.Visible:=True;
end;
关于delphi - 在 TListView 中就地编辑子项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10835355/
我正在使用 Embarcadero 的 C++ Builder XE8。我有一个 ListView 并动态添加列及其项目。我需要一个图像列表,因为我想使用 (ListItem->SubItemImag
我正在尝试在 TListView 中放置一个图标当某些行显示时,我有 TImageList与加载的图像,但它没有连接。我的代码是这样的 with sListView2 do begin test
当使用 TListView 并且主题在应用程序中被禁用时,焦点和选定的项目显示如下: 注意两个图像中三角形所在的位置。项目的绘制框不会在图标出现的位置绘制。在 TListBox 中,绘制的项目填充整个
我已经使用 TListView 制作了我的应用程序,以将主数据集显示为列表作为导航记录的方式。我已将 LiveBindings 与 Sync * 连接一起使用。 主要问题是它将整个表加载到内存中。大
我有一个 TListView 的后代,它提供了一些附加功能,例如排序和从 TDataset 加载自身的能力。我现在希望进一步扩展这个组件,以便在将项目添加到 ListView 时可以指定绘图的某些方面
TListView 控件是否有一个在控件滚动时触发的事件? 我宁愿不必对 TListView 控件进行子类化。 最佳答案 这非常有效,但可能会违反您问题的限制。 在包含使用 TListView 的表单
编写 FMX 应用程序并使用以下文档... http://docwiki.embarcadero.com/RADStudio/Berlin/en/Customizing_FireMonkey_List
我创建了 ListView 并添加了复选框来检查每一行(如果需要)。一切都很好,直到 ListView 中有很多项目,因此需要对其进行排序。我在线检查,然后发现如果滚动滚动条,复选框不会与其他内容一起
我正在对 tlistview 进行编程,以便它从右到左显示其列(以便正确显示希伯来语文本)。我在表单的创建方法中使用以下代码,其中“lv”是 ListView SetWindowLong (lv
我有一个包含 3 列的 Tlistview,我需要来自 Tcollection 对象,如下所示 FListeDispoProduit := TListeDispoProduit.Create(TPro
我有一个显示小缩略图的TListView(ViewStyle:=vsIcon)。在运行时,我将图像分配给项目: for i := 0 to Total - 1 DO with ListVie
我正在使用 Delphi 2010,并且我试图允许用户在 TListView 中的每行 2 个选项之间进行选择。使用 TListView,我可以将样式设置为 vsReport 并启用复选框,但这只会让
当项目添加到 TListView 时,如何捕获事件? 根据文档,我认为 OnInsert 事件可以完成这项工作。它甚至将实际的 TListItem 对象传递给处理程序: OnInsert Occurs
是否可以修复 TListView 中 subitem 图像的绘制,以便它们不会如图所示在左侧被截断? 最佳答案 嗯,Pieter van Wyk,我做了一个简单的示例,展示了如何自行绘制 TListV
使用标准 TListView 组件 (ViewStyle = vsReport),我附加了一个 TImageList 并成功将图像添加到第一列 (Item.ImageIndex := 0) )以及后续
带有 FireMonkey 的 Delphi 10.4.1。 我在 TListView 上有 50 个项目,ID 从 1 到 50。这里没有发布代码,因为我什至不知道从哪里开始。 如果我搜索 ID=3
我需要更改我的 listView 的所有标题的背景颜色以突出显示它们。我在 Object Inspector 上一无所获,在 Style Designer 上也一无所获,你们能给我一些指导吗? 最佳答
我有一个 ViewStyle 设置为 vsReport 的 TListView。如何更改网格的颜色和网格线的宽度。 D2009 中的网格线有点太粗了,我想要与 D5 中的宽度相同。 谢谢 最佳答案 没
我正在使用 TListView我已经成功地填充了每个项目的标题和第一个子项目。请参见下面的示例。 user pass working status valid data1 pass -
我有一个包含 4 列的 TListview(当然都是字符串),但是,我在其中存储数据: 标题:任意字符串 SubItems[0]:整数,例如'5016' SubItems[1]:日期,例如'03/22
我是一名优秀的程序员,十分优秀!