I use the UltraGrid in my C# winforms app by binding it to strongly typed objects, which are generated by a code generater. So each grid is in effect bound to a table in the underlying database.
Every now and again, I will make changes to the database, usually by adding fields to existing tables. This causes a few problems in my UltraGrids. When I re-generate the code (and hence the strongly typed objects), the grids automatically get new columns, and I am forced to change some properties of the new columns in the UltraGrids if I dont want these new columns showing:"ExcludeFromColumnChooser" from Default to True"Hidden" from False to True.
This is getting a bit tiresome. It is getting such that I am put off adding new fields, as it is quite a task finding all of the grids I need to manually exclude the fields from.
Is there an easier way to do this? I would prefer if the default behaviour was that new columns were hidden, and excluded from the column chooser.
Thanks.
----- EDIT ----
Just discovered there is a NewColumnLoadStyle property, that does half of what I want - it sets new columns to "Hidden = true". This does not sort out the ExcludeFromCOlumnChooser thing though - this is still the default (which is to show).
It will be a pain to set the default column chooser thing to false, as t hat would mean I would need to hunt down every column that needs to be in the chooser and set it from default to true...
It does seem like you are over-complicating things a bit.
All you have to do is determine which columns should be available to the user. Once you do that, it's just a matter of placing code in the InitializeLayout event of each grid and looping through the column. For each column in the grid, you check the key. If the column should be available to the user, you do nothing. If it should not (or it's a new column that you don't recognize) you set Hidden to true and ExcludeFromColumnChooser to true.
You can also set NewColumnLoadStyle if you want to, but the loop in the InitializeLayout event makes it redundant since it will hide the column, anyway.
I am assuming that your application is saving the grids layout so that if the user hides a column and re-runs the application, that column is still hidden. If that assumption is wrong and you are NOT saving the layout, then there is an even easier way for you to handle this. If you are not saving (and loading) the layout, then any columns which are already hidden when you run the application are hidden by you, the developer. You can therefore assume that any hidden columns should also be excluded from the columnchooser. So you could loop through the columns in InitializeLayout and set ExcludeFromColumnChooser to true on any column whose Hidden property is true.
Mike Saltzman"]Why is this such a pain? All you have to do is loop through the columns in the InitializeLayout event of the grid and set Hidden to true and ExcludeFromColumnChooser to true on all except the columns you want the user to see. Presumably, you can determine this by simply running your application and looking at the columns that are visible now.
The problem is that this project is a few years old, with many many grids in it already, using a number of different table. A number of the grids use the same table, only with different fields hidden/displayed.
According to my understanding, to get the behaviour I'm after, I'm going to need to do the following:
Its that last step that will be the killer. There are a lot of grids, with a lot of columns.
The end result of this is that the default behaviour will be for new fields to be hidden and excluded from column chooser by default, and will need to manually change both settings to see them.
Let me know if it seems I'm making this too complicated for myself.
Hi,
fweeee said:It will be a pain to set the default column chooser thing to false, as t hat would mean I would need to hunt down every column that needs to be in the chooser and set it from default to true...
Why is this such a pain? All you have to do is loop through the columns in the InitializeLayout event of the grid and set Hidden to true and ExcludeFromColumnChooser to true on all except the columns you want the user to see. Presumably, you can determine this by simply running your application and looking at the columns that are visible now.