2012-04-12 51 views
1

我已经为processdialogkey()创建了一个Datagridview类。但是荫得到以下错误...任何机构可以帮我请...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 

回答

1

系统:视窗:: Forms :: Keys是一个枚举,因此是一个值类型(不是引用类型)。所以,要匹配你想删除帽子的基类方法的签名(^)。一般来说,除非你确实需要拳击行为,否则你不应该使用具有值类型的帽子。

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

+0

感谢Matt..It帮助我很好,工作葡萄酒....我得到明确.... – user1328559 2012-04-14 07:00:16