同意 plainsong(轻风)的,用一个TEdit控件,选中一行则移动TEdit到该行列,可在TListView的OnCustomDrawSubItem事件中处理。下面是我用一个TComboBox代替TEdit的代码:(供参考) procedure TFm_DutyAtta.LV_DataCustomDrawSubItem(Sender: TCustomListView; Item: TListItem; SubItem: Integer; State: TCustomDrawState; var DefaultDraw: Boolean); var iLeft,i:Integer; begin inherited; if Item.Selected then begin ileft:=0; for i:=0 to 2 do ileft:=ileft+lv_Data.Columns[i].Width; //CmB_Attribute.Text:=trim(Item.SubItems[2]); if trim(Item.SubItems[2])='所需资料' then CmB_Attribute.ItemIndex:=0 else CmB_Attribute.ItemIndex:=1; if Item.Checked then CmB_Attribute.Enabled:=true else CmB_Attribute.Enabled:=false; CmB_Attribute.Visible:=true; CmB_Attribute.Width:= LV_Data.Columns[3].Width; CmB_Attribute.Top:=Item.Top-2; CmB_Attribute.Left:=lv_Data.TopItem.Left+ileft-18; end else try if (LV_Data.Items[LV_Data.ItemIndex+1].Top=LV_Data.TopItem.Top) or (LV_Data.Items[LV_Data.ItemIndex].Top>LV_Data.ClientHeight) then CmB_Attribute.Visible:=false; except end; end;
listview.selected.subitems.substring[3]:=......
在TListView.OnMouseDown和TListView.OnMouseMove中判断鼠标操作,当在被选中的Item上点击左键时,判断出应该编辑哪一列,把Edit移动合适的位置,设置Text属性,设为焦点.
监视Edit的OnExit事件和OnKeyDown(Key=VK_RETURN)事件,这时用Edit.Text修改相应ListItem的Caption或SutItem,并把Edit隐藏。
做起来比较复杂,要考虑到很多情况,如果是我,宁可在双击时弹出一个对话框去修改这个Item.
如果是创建TEdit控件的话,那么每个TEdit的NAME等有一大堆问题,
而且这份工作比较紧急,所以自己也不可能花很多的时间去编写。
或者是不是可以考虑用其他的控件来实现?希望大家能够帮帮我,多谢!!!!!
你可以控制ListView的显示顺序呀,就是让你需要的修改字段放在第一栏的位置上就可以了;
procedure TFm_DutyAtta.LV_DataCustomDrawSubItem(Sender: TCustomListView;
Item: TListItem; SubItem: Integer; State: TCustomDrawState;
var DefaultDraw: Boolean);
var
iLeft,i:Integer;
begin
inherited;
if Item.Selected then
begin
ileft:=0;
for i:=0 to 2 do
ileft:=ileft+lv_Data.Columns[i].Width; //CmB_Attribute.Text:=trim(Item.SubItems[2]);
if trim(Item.SubItems[2])='所需资料' then
CmB_Attribute.ItemIndex:=0
else CmB_Attribute.ItemIndex:=1; if Item.Checked then CmB_Attribute.Enabled:=true
else CmB_Attribute.Enabled:=false; CmB_Attribute.Visible:=true;
CmB_Attribute.Width:= LV_Data.Columns[3].Width;
CmB_Attribute.Top:=Item.Top-2;
CmB_Attribute.Left:=lv_Data.TopItem.Left+ileft-18;
end
else
try
if (LV_Data.Items[LV_Data.ItemIndex+1].Top=LV_Data.TopItem.Top)
or (LV_Data.Items[LV_Data.ItemIndex].Top>LV_Data.ClientHeight) then
CmB_Attribute.Visible:=false;
except
end;
end;