Lose focus on active control when calling RefreshReport() method for ReportViewer

3 posts, 1 answers
  1. Danilo
    Danilo avatar
    47 posts
    Member since:
    Sep 2012

    Posted 22 Jan 2015 Link to this post

    Hello everyone

    In my application I have a Telerik.Reporting.ReportViewer to load a preview of a report. I also have many controls like RadTextBox or RadDropDownList etc. What I'm trying to do is when the user changes the text of a RadTextBox it should reload the ReportViewer. To do this I'm using RefreshReport() method. But when I call this method it loses the focus on the textbox. I already tried refocus the control after calling the RefreshReport() method but this didn't work neither. I found this thread of October 2009:

    http://www.telerik.com/forums/winforms-report-viewer-quot-refreshreport-quot-sets-focus

    I'm wondering now, 5 years later, if there is a way to prevent losing focus on the control when calling RefreshReport() method?

    Ah, if you want to have a look at my code, here it is:

    InstanceReportSource report = new InstanceReportSource();
    reportSpedi.ReportSource = new Spediauftrag(this);
    reportSpedi.RefreshReport();

    // active textbox
    txtSpediGewicht.Select();

    Regards,
    Danilo
  2. Answer
    Stef
    Admin
    Stef avatar
    3610 posts

    Posted 26 Jan 2015 Link to this post

    Hi Danilo,

    On refreshing the report the focus will be taken from the external UI, but you can use the exposed WinForms ReportViewer API to set back the focus to the desired control OnUpdateUI:

    public Form1()
    {
        InitializeComponent();
        reportViewer1.UpdateUI += reportViewer1_UpdateUI;
        reportViewer1.ReportSource = new InstanceReportSource { ReportDocument = new Report1() };
        reportViewer1.RefreshReport();
    }
     
    void reportViewer1_UpdateUI(object sender, EventArgs e)
    {
        textBox1.Select();
    }


    Let us know if you need any further help.

    Regards,
    Stef
    Telerik
     

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

     
  3. Danilo
    Danilo avatar
    47 posts
    Member since:
    Sep 2012

    Posted 02 Feb 2015 in reply to Stef Link to this post

    Hi Stef,

    Thank you very much, it's working fine now.

    Regards,
    Danilo
Back to Top