DataGridView Freezing upon loading around 1000 r / 7 c

Ask questions about creating Graphical User Interfaces (GUI) in PowerShell and using WinForms controls.
Forum rules
Do not post any licensing information in this forum.

Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
Locked
User avatar
Srinath
Posts: 111
Joined: Tue Oct 09, 2012 6:24 am

DataGridView Freezing upon loading around 1000 r / 7 c

Post by Srinath »

Hello,

In PowerShell Studio 2012, I created a DataGridView.

Using background job script (via Job Tracker) I pulled up all users information from Active Directory. Instead of getting all properties for each user, I specified 7 properties - this is occurred in background job.

Once it completes the job, it come out of Job Tracker. The next step is to load data into Table followed by DataGridView.

Here is the problem. When it is loading the result which contains around 1000 rows and 7 columns, it causing the application to "not responding" state.

Is there any better way to handle this? Any comments would be greatly appreciated.

Thank you!

User avatar
davidc
Posts: 5913
Joined: Thu Aug 18, 2011 4:56 am

Re: DataGridView Freezing upon loading around 1000 r / 7 c

Post by davidc »

FYI I moved the post to the PowerShell GUI forums.

Creating a DataTable is slow and you can skip that step (but you lose free sorting). The fastest and more complex method is to manually add a row each time you use Receive-Job to get the partial results.

I would have recommended building the Table in the Job, but PowerShell has the annoying habit of changing objects in the pipeline. Instead of a DataTable you will get an array of DataRows which the DataGridView doesn't support.

David
David
SAPIEN Technologies, Inc.

User avatar
Srinath
Posts: 111
Joined: Tue Oct 09, 2012 6:24 am

Re: DataGridView Freezing upon loading around 1000 r / 7 c

Post by Srinath »

Sorry, I'm having hard time in figuring out right forum to post questions...

Thanks for your suggestions. Sorting code snipped that shipped with DatagridView template is really helpful.

After going through the MSDN article (http://social.msdn.microsoft.com/Forums ... 9210420cd/), I'm able to gain huge performance boost once I reset the following settings:

AutoSizeColumnsMode: DisplayedCells
AutoSizeRowsMode: DisplayedCells

Previously I set both options to: AllCells.
I would have recommended building the Table in the Job, but PowerShell has the annoying habit of changing objects in the pipeline. Instead of a DataTable you will get an array of DataRows which the DataGridView doesn't support
Is there anyway to bypass this? Thanks for your prompt response.

User avatar
davidc
Posts: 5913
Joined: Thu Aug 18, 2011 4:56 am

Re: DataGridView Freezing upon loading around 1000 r / 7 c

Post by davidc »

This forum is for any GUI related questions, such as questions on controls.

If you have questions directly related to the product such as an issue with the application then use the Product Forums.

Ahh yes the sizing could make a big difference.

As for bypassing PowerShell's conversion, you could try wrapping the DataTable in a PSObject and set the Table as a note property. I haven't tried it so I don't know if it will work or not.

David
David
SAPIEN Technologies, Inc.

jvierra
Posts: 14545
Joined: Tue May 22, 2007 9:57 am
Contact:

Re: DataGridView Freezing upon loading around 1000 r / 7 c

Post by jvierra »

The defult setting for this grid is 'None' When doinglarge lopads this is the correct setting. To autosize the grid do a manual autosize after the grid is completely loaded. This can be accomplished by settinging autosize to all and then refreshing the grid.

If you set autosize to any other setting it will autosize the row and may autosize the whole grid if any element of the new row exceeds the current maximum.

By using Davids suggestion of wrpping the dataset you will only simplify the code. The addition will still behave much the same way.

Locked