Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9159369
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T13:28:32+00:00 2026-06-17T13:28:32+00:00

One of our customers hosts our WinForms .NET grid control iGrid.NET ( http://www.10tec.com/ )

  • 0

One of our customers hosts our WinForms .NET grid control iGrid.NET (http://www.10tec.com/) inside a WPF ElementHost container together with other WPF controls. It may look strange as it’s a WinForms control inside a WPF host inside a WinForms form, but they have no choice because of the other WPF stuff they use (it’s the AvalonDock http://avalondock.codeplex.com/ docking container).

The problem is that our .NET datagrid control’s infrastructure requires to know the parent WinForms form, but the following construction we use for that always return null in this situation:

Form myTopLevelOwnerForm = fCurrentGrid.TopLevelControl as Form;

I.e. the standard Control.TopLevelControl property intended for this purpose returns null – though most likely it should be so in the case of WPF host.

The question is: are there other ways to know the parent form from the current control’s code? Say, using WinAPI handles or better other native .NET memebrs?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T13:28:34+00:00Added an answer on June 17, 2026 at 1:28 pm

    The following code works. At least, in our project 🙂

    // API declaration
    [System.Runtime.InteropServices.DllImport("user32.dll", ExactSpelling = true, CharSet = System.Runtime.InteropServices.CharSet.Auto)]
    public static extern IntPtr GetParent(IntPtr hWnd);
    
    // Main code snippet
    Control myTopLevelControl = fOwner.TopLevelControl;
    
    if (myTopLevelControl == null)
    {
        IntPtr handle = fOwner.Handle;
        while (true)
        {
            IntPtr parentHandle = GetParent(handle);
            if (parentHandle == IntPtr.Zero)
            {
                myTopLevelControl = Control.FromHandle(handle) as Form;
                break;
            }
            handle = parentHandle;
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

My ASP.NET application is running on IIS6. Today one of our customers encountered an
We are a lead generating company and have developed one application where our customers
We developed an asp.net website for one of our customer. We followed our rules
We are running several the same ASP.NET applications (one per customer) based on our
One of our customers experiences problem with our streaming application (win32). It seems like
One of our customers does not want to put the default instance name MSSQLSERVER
I've got a bug from one of our customers and believe that the problem
I have a website where everytime one of our customers reviews a new product
One of our customers said they have a very simple script which uses fsockopen()
One of our customers is trying to connect to an Oracle database with the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.