Good afternoon.
Give, please, a code example, how to realize hierarchical datasource as a collection.
I attach a project that should work according to the instructions, but don't work correctly.
Thanks for reply.
Some of the given variants don't work, such as setting NewColumnLoadStyle at design-time or at run-time. Using InitializeLayout event doesn't work as well. Anyway, for answering on this thread it would be better to provide some working code here or a reference to existing resources.
I've got a decision that is a "workaround", but it works and may be useful.
1. Don't desing datagrid fields.
2. Set ultrawingrid datasource as collection.
3. Hide all the columns in a band iteratively.
4. With reflection dynamically get string names of the properties you need to show as fields.
5. Set for these properties Header.VisiblePosition, Header.Caption and Hidden=false.
The advantages of this variant are
- if any property name changes, you get a complilation error.
- If any two properties change places in class file, that will not affect the view.
- If any property is added, that will not affect the view.
- You can save and restore layout for all the bands.
Hi,
I'm not sure I am following you.
The sample you attached here is not setting NewColumnLoadStyle until run-time. If your actual application is setting up the layout at design-time, then this will only affect new columns added at run-time after you already bound the grid, so that doesn't make a lot of sense.
What's the problem with setting the Hidden property of the column(s) at run-time? One way or another you have to decide which columns are visible and which are not.
If someone adds a new column to the data source, then NewColumnLoadStyle (if set at design-time) will determine if that new column is visible by default. It can only default to hidden or not hidden.
In your original post, you seemed to indicate that you wanted it hidden by default, so that whoever adds it doesn't accidentally add a column to the grid without realizing it. So the solution to that is to set NewColumnLoadStyle on the grid at design-time. Setting it at run-time won't do any good there, anyway.
The other option I presented is to use the InitializeLayout event and hide all of the columns except the ones you want to show. This will have essentially the same effect as setting NewColumnLoadStyle at design-time - any new columns added to the data source will not automatically display in the grid without someone taking some action.
Either way, the new columns won't show up unless someone takes action to make them show up.
I don't understand what else you are looking for here.
I tried NewColumnLoadStyle property, but it didn't work for me: no columns are shown at all. I'm attaching a modified project. Looping is a solution but not a flexible one, because there's no point to set the schema in ultrawingrid designer.
What solution is suitable for the attached project?
It sounds like what you want is the NewColumnLoadStyle property:
private void ultraGrid1_InitializeLayout(object sender, Infragistics.Win.UltraWinGrid.InitializeLayoutEventArgs e) { UltraGridLayout layout = e.Layout; layout.NewColumnLoadStyle = NewColumnLoadStyle.Hide; }
Another option would be to loop through all of the columns and set Hidden to true on all of the columns that you do not explicitly want to be visible.
Thanks, the situation became almost clear for me. The browsable attribute works, hidden property works, too.
However, setting hidden property is inconvenient, because of a new field may appear in any time by any developer that isn't even aware that a class is used as datasource. For the same reason that developer may forget to mark Browsable attribute.
It is interesting how to make it work using not including the field in my DataSource.
Let in my example class B have an additional property
public int F{get; set; }
That property should not be included into datasource.
I can suggest a correct, but hard way - to define a class D that contains only needed fields and define a converter B into D and use D as datasource. Also, one can create a datasource object with rows (the datasource is already a table, not collection). But isn't there a more simple solution?