-
April 9th, 2012, 03:06 AM
#1
[RESOLVED] Convert from C# to VC++2010 -dataGridView?
Hi,
I like to convert the following codes from c# to VC++2010. Any help for me?
Actually the codes for dataGridView - Enter Key process for cursor movement from one cell to another cell [like a tab key...]
public class MyDataGrid : DataGridView
{
protected override bool ProcessDialogKey(Keys keyData)
{
Keys key = keyData & Keys.KeyCode;
if (key == Keys.Enter)
{
base.OnKeyDown(new KeyEventArgs(keyData));
return true;
}
else
{
return base.ProcessDialogKey(keyData);
}
}
}
-
April 9th, 2012, 04:46 AM
#2
Re: Convert from C# to VC++2010 -dataGridView?
Just thinking about "translating" C# into (Visual) C++ code is a "piece of cake".
However, DataGridView Class is .NET stuff, then you cannot simply derive from it "like a walking in the park", let's say, in an MFC application.
Basically, I see two choices:
- get rid of .NET's DataGridView and replace it with an unmanaged component, e.g. "Microsoft Data Grid" ActiveX control, or
- make a separate .NET Class Libray project to implement the grid, then "import" it in the MFC application; not sure about this one, but may try this article as a "start digging point".
Last edited by ovidiucucu; April 9th, 2012 at 04:54 AM.
-
April 10th, 2012, 03:41 PM
#3
Re: Convert from C# to VC++2010 -dataGridView?
As Ovidiu said, it's no picnic to convert to native C++, but if you are one of the handful of people in the world coding in C++/CLI, then you can use:
Code:
public ref class MyDataGrid : DataGridView
{
protected:
virtual bool ProcessDialogKey(Keys ^keyData) override
{
Keys ^key = keyData & Keys::KeyCode;
if (key == Keys::Enter)
{
DataGridView::OnKeyDown(gcnew KeyEventArgs(keyData));
return true;
}
else
{
return DataGridView::ProcessDialogKey(keyData);
}
}
};
-
April 11th, 2012, 10:30 AM
#4
Re: Convert from C# to VC++2010 -dataGridView?
Hi David,
The above code will be declared in Header File..Then, how this can be initiated in cpp File?
Can you explain me please?
Thanks
-
April 11th, 2012, 04:03 PM
#5
Re: Convert from C# to VC++2010 -dataGridView?
Code:
//.h file code:
public ref class MyDataGrid : DataGridView
{
protected:
virtual bool ProcessDialogKey(Keys ^keyData) override;
};
//.cpp file code:
bool MyDataGrid::ProcessDialogKey(Keys ^keyData)
{
Keys ^key = keyData & Keys::KeyCode;
if (key == Keys::Enter)
{
DataGridView::OnKeyDown(gcnew KeyEventArgs(keyData));
return true;
}
else
{
return DataGridView::ProcessDialogKey(keyData);
}
}
-
April 12th, 2012, 06:24 AM
#6
Re: Convert from C# to VC++2010 -dataGridView?
Hi David,
I Checked...Its giving the following errors. Further is it possible to learn.....?
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
Thanks For the helps...
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|