【问题标题】:VCL TListView and EditCaption()VCL TListView 和 EditCaption()
【发布时间】:2019-02-16 03:34:12
【问题描述】:

在 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】:

    难道没有一种方法可以执行 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);
            }
        }
    }
    

    【讨论】:

      猜你喜欢
      • 2019-09-20
      • 2016-01-19
      • 1970-01-01
      • 1970-01-01
      • 2015-07-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多