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.
This topic is 4 years and 1 month old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
You cannot set that on individual columns. You can only set the global column alignment for all columns.
Because the style object is set by type the properties of the style object appear when you look but they are inherited from the global template and cannot be set. The property does not exist on individual columns.
Your issue seems to be because you are trying to change the style after the grid has been loaded. Set teh style for the cells only before the grid is loaded and displayed.
You can also probably do this after the grid is loaded by creating a new style object and adding assigning it to the DefaultCellStyle property.
iamtj69 wrote: ↑Fri Feb 14, 2020 4:22 am
Does something similar apply for disabling "sort". This is something else i have been struggling with. How can i disable 'sort' for an entire grid?
There is no sort for a grid. The data displays however it is loaded.
That doesn't "unsort" data. There is no way to "unsort" data. That just tells the grid how it will be sorted. If you choose "Automatic" then the grid will be sorted on that column. If the grid is already loaded it will not be changed when you change the value. To autosort you need to use a DataTable and then there is still no way to unsort the data.
Think about it. It is impossible to ever unsort something. We can remember some previous order and sort it by that order but we still have to sort it to get there.
Once you sort by any column your only option is to sort by a different column. With a DataTable we can apply a data sort to the view and we can remove the sort filter on the view. This would return the grid to its default view which may be what you are asking.
I was just trying to disable the ability for a user to sort any column in the datagridview (i have achieved this now), i wasn't trying to "unsort" any columns.
The data comes pre-sorted from an SQL database as a dataset (collection of datatables). I then populate several Datagridviews on a form with these tables.
One table in particular has over 50,000 rows, so can hang if someone tries to sort by a column. I simply wanted to disable the ability to sort.
Columns do not sort automatically. If you design the grid to to set the column to NotSortable in the designer then they won't be clickable. If you load the grid from a DataTable then try to disable the mode it will cause the columns to be reset because they are being "de-buttoned" but it will cause the columns to be non-sortable.
This topic is 4 years and 1 month old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.