CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 14 of 14

Hybrid View

  1. #1
    Join Date
    Dec 2011
    Posts
    73

    [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);
    }
    }
    }

  2. #2
    Join Date
    Feb 2003
    Location
    Iasi - Romania
    Posts
    8,234

    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:
    1. get rid of .NET's DataGridView and replace it with an unmanaged component, e.g. "Microsoft Data Grid" ActiveX control, or
    2. 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.
    Ovidiu
    "When in Rome, do as Romans do."
    My latest articles: https://codexpertro.wordpress.com/

  3. #3
    Join Date
    Aug 2005
    Posts
    198

    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);
    		}
    	}
    };
    David Anton
    Convert between VB, C#, C++, & Java
    www.tangiblesoftwaresolutions.com
    Instant C# - VB to C# Converter
    Instant VB - C# to VB Converter

  4. #4
    Join Date
    Dec 2011
    Posts
    73

    Thumbs up 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

  5. #5
    Join Date
    Aug 2005
    Posts
    198

    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);
    	}
    }
    David Anton
    Convert between VB, C#, C++, & Java
    www.tangiblesoftwaresolutions.com
    Instant C# - VB to C# Converter
    Instant VB - C# to VB Converter

  6. #6
    Join Date
    Dec 2011
    Posts
    73

    Smile 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
  •  





Click Here to Expand Forum to Full Width

Featured