c++ - DataGridView 类 - 错误()

标签 c++ datagridview c++-cli

我已经为 processdialogkey() 创建了一个 Datagridview 类。但是我遇到了以下错误......任何人都可以帮助我......

这段代码:

//Header File MyDGV.h

    public ref class MyDGV : public DataGridView
    {
    protected:
        virtual bool ProcessDialogKey(System::Windows::Forms::Keys^ keyData) override;
    };

//MyDGV.CPP File
#include "StdAfx.h"
#include "MyDGV.h"

bool MyDGV::ProcessDialogKey(System::Windows::Forms::Keys^ keyData)
{
    Keys^ key = keyData & (System::Windows::Forms::Keys::KeyCode);
    if (key == System::Windows::Forms::Keys::Enter)
    {
        DataGridView::OnKeyDown(gcnew KeyEventArgs(System::Windows::Forms::Keys^ keyData));
        return true;
    }
    else
    {
        return DataGridView::ProcessDialogKey(System::Windows::Forms::Keys^ keyData);
    }
}

导致以下错误:

Errors:
01. warning C4490: 'override' : incorrect use of override specifier; 'MyDGV::ProcessDialogKey' does not match a base ref class method
02.error C3063: operator '&': all operands must have the same enumeration type
03.error C2275: 'System::Windows::Forms::Keys' : illegal use of this type as an expression
04.error C2275: 'System::Windows::Forms::Keys' : illegal use of this type as an expression

最佳答案

System::Windows::Forms::Keys 是一个枚举,因此是一个值类型(不是引用类型)。因此,要匹配要删除帽子 (^) 的基类方法的签名。一般来说,除非您确实需要装箱行为,否则不应将帽子与值类型一起使用。

http://msdn.microsoft.com/en-us/library/system.windows.forms.keys.aspx

关于c++ - DataGridView 类 - 错误(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10120383/

相关文章:

c++ - 打印 float 的精确值

c# - 如何将时间列显示为 hh :mm tt in datagridview which is retrieved from MYSQL time field?

c# - 点击datagrid View 的按钮列,一封自动邮件将被发送到邮件id

c# - 数据 GridView 未在 win 窗体 c# 中显示更新的数据?

c# - 在 C# 中使用 C CLR::Class Library

c++ - 如何将结构作为指针传递? [C++]

c++ - else if作为逻辑语句怎么写?

c++ - 如何实现综合基准?

.net - 销毁具有静态存储持续时间的本地对象

string - 如何将char *转换为System::string ^