Hello support,
I my business objects I have some properties, that are used for administration and I don't want to offer them to potential users - so they would not be visible in a column chooser form, but in the ObjectModel view, they would be simply unchecked, so that user could add them if they would like to. I cannot use Browsable(false) attribute because it would hide the property for all users.
Basically I have to delete some nodes in IModelListView's Columns collection. At first I used custom model generator, found here: ModelViewsNodesGenerator Class, but I found that it works with application model on default level, which means any model differences, for example changed editor type or cloned views are not present here, so this approach is not usable for me.
Then I found out that in this scenario I can catch Application.SetupComplete event, found in a following ticket: How to change the default Application Model value globally or for multiple nodes, and at this point model is fully updated with exception of user model differences, which is exactly what I needed. My logic is that I get all model list views from application model and filter them according to my needs. Then I get collection of distinct types, which are present amongst the views and for each type I get the list of properties I'd like to hide.
The main problem for me is that the operation of removing columns takes too long - about 8 to 10 seconds for about 800 views. I'm currently using Parallel.ForEach, but when I tried it with sequential foreach, it took more than 1 minute. Sadly even 8 more seconds of a startup of a win application is really long time.
Here is sample of my code:
C#private void Application_SetupComplete(object sender, EventArgs e)
{
// get list of model views to process
filteredListViews = Application.Model.Views.Where(...).ToList();
Parallel.ForEach(filteredListViews, (viewNode) =>
{
var view = viewNode as IModelView;
if (view is IModelListView modelListView)
{
var propertiesToHide = // get properties to hide according to a model class of a model view
foreach (var property in propertiesToHide)
{
var column = modelListView.Columns[property.Name] as IModelColumn;
if (column != null)
{
column.Remove();
}
}
}
});
}
I'd like to ask if this is the right way of customizing application model before application start. Or if removing nodes is really a longer procedure, then if you could recommend different approach.
Thank you.