VCL的TListView和EditCaption()

问题描述 投票:1回答:1

在C ++ Builder中,我有一些带有一些项目的TListView

每当有人输入数值时,它应该应用于ListView中当前选定的TListItem的标题:

void __fastcall TFormMain::ListViewKeyDown(TObject *Sender, WORD &Key,
  TShiftState Shift)
{
    if ( Key >= '0' && Key <= '9' )
    {
        if ( !ListView->IsEditing() )
        {
            ListView->Selected->EditCaption();
        }
    }
}

此代码“以某种方式”工作:输入数值会使TListView进入编辑模式。然后我必须重新输入数字以将其应用于TListItem的标题。

有没有办法做EditCaption()并只在一个步骤中应用数字?

c++builder vcl tlistview
1个回答
1
投票

有没有办法做EditCaption()并只在一个步骤中应用数字?

您必须在调用后手动将键入的数字转发到ListView的编辑器,例如:

void __fastcall TFormMain::ListViewKeyDown(TObject *Sender, WORD &Key, TShiftState Shift)
{
    if ( (Key >= '0') && (Key <= '9') )
    {
        TListItem *Item = ListView->Selected;
        if ( (Item) && (!ListView->IsEditing()) )
        {
            Item->EditCaption();

            HWND hWnd = ListView_GetEditControl(ListView->Handle);

            TCHAR str[2] = {TCHAR(Key), 0};
            SetWindowText(hWnd, str);
        }
    }
}
© www.soinside.com 2019 - 2024. All rights reserved.