How to get Spread object from window handle?

Posted by: abhi-fp on 8 September 2017, 11:51 am EST

  • Posted 8 September 2017, 11:51 am EST

    We are doing test automation for one of the Microsoft application which uses Farpoint spread 1.0.4.0 & 1.0.9.0 . The application is made on .NET 2.0. As a part of automation we are required to read the data shown on spread to verify its content. Using Microsoft internal testing tool we are able to get the window handle for Spread control in winform but we have to get spread control object to read through the rows.

    Can anyone please let us know how to get the spread control from window handle in C#? OR does Spread expose any Win32 API to get hold of spread object.

    Please let me know if more info is required or if question is not clear.

    TIA,

     

  • Posted 8 September 2017, 11:51 am EST

    The DotNet framework provides a FromHandle method in the Control class.  The returned value is of type Control which can then be cast to type FpSpread.



        Control c = Control.FromHandle(handle);

        if (c is FpSpread)

        {

            FpSpread s = (FpSpread)c;

            …

        }

  • Posted 8 September 2017, 11:51 am EST

    Hello,



    Spread does not have a method for this, but you should be able to loop the Controls collection comparing the handle of each control to the hwnd you have stored. Here is some sample code to do this.



          FarPoint.Win.Spread.FpSpread ss;<?xml:namespace prefix = o ns = “urn:schemas-microsoft-com:office:office” /><o:p></o:p>

          foreach(Control c in this.Controls)<o:p></o:p>

          {<o:p></o:p>

            if(hwnd==(int)c.Handle)<o:p></o:p>

            {<o:p></o:p>

              ss = (FarPoint.Win.Spread.FpSpread)c;<o:p></o:p>

              //Add code here to access the ss object<o:p></o:p>

              MessageBox.Show(ss.Sheets[0].GetValue(1,1).ToString());<o:p></o:p>

            }<o:p></o:p>

          }<o:p></o:p>



     

  • Posted 2 April 2019, 10:00 pm EST

    Is it possible to get the spread control from another process?

    Thanks a lot for your help.

Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels