Datagridview vertical scroll bar problem when using thread? RRS feed

  • Question

  • Hi..
    I have a datagridview for showing the reports. Here the datagridview vertcial scroll bar wont workbut it show the both horizonadal, vertical bar.but horizadal bar only worked anot vertical  bar.

    I have explained my process. I have  taken a report from Exchange server and stored the Sql database. After finishing the data collection then I have again select some of the fileds only from Database via datatable. I have copied my datagridview using datagridview datasource.
    Here I have showed another form  using showdialog with passing the datagridview reference object via constructor and that form have only the animated progress bar
    In that form I have used a secondary thread for showing the animated progress, and the secondary thread only do this all datacollection process including datagridview data source. after finishing all the process I have used the delegate for close the form. Now my main GUI Datagridview have all the result. but the vertical scroll bar only didnot work. that means it display likw hanged(vertical scroll bar only). In that time I have minimized and maximaized my Form than the vertical shroll bar nto showed properly.
    Note: Already I have set the datagridview scrol bar property :both. also I have used the cell painting event in my main GUI.

    As I found this type of secondary thread process with datagridview reference object occured that problem.
    In my same  task Suppose I have used this  datagridview.datasource=dt line
    in my Main Gui there is not any problem and both scroll bar worked.

    So How can i solve this problem.
    Pls help me..
    A PathFinder.

    Friday, July 22, 2011 2:20 AM


  • First thing. You cannot access UI elements through secondary threads. And if you want to do so, you must use a  delegate to perform this. There is a special kind of delegate called 'MethodInvoker'. You can make use of it. For example, you have below function to update the progress bar:

    public void UpdateProgressBar()
        //you have code to change the progress bar status here

    Now, you just can't call this function from a background thread because this function interacts with UI. So, you can use MehtodInvoker to call this function as below.

    public void SecondaryThreadFunction()
         MethodInvoker mi = new MethodInvoker(UpdateProgressBar);
         this.Invoke(mi);   //update progress

    Try this method.

    Please mark this post as answer if it solved your problem. Happy Programming!
    • Marked as answer by Cookie Luo Wednesday, August 3, 2011 5:53 AM
    Friday, July 22, 2011 6:07 AM