I need to use a custom class which returns a generic.list object. I can make it the datasource and get it to display great. I would like to manipulate the columns (add, hide, etc) at runtime. I seem to either be putting the wrong keywords in the search or something. FYI, I am a nubee to Infragistics toolset.
Hi Matt,
Hiding a column is as simple as setting the Hidden property on that column. If that's not working for you, then my best guess is that something your application is blowing away or replacing that setting.
If I were you, I'd put a button on your form and put code in the Button_Click and then display the Hidden property of the column in the Output window.
Debug.Writeline(grid.DisplayLayout.Bands[0].Columns["my column"].Hidden);
That will allow you to verify if the Hidden property is still set to true. If it's not (as I suspect), then you try to track down what else is setting it.
Search the code for "Hidden" to see if you are setting it somewhere else.
Also, check your code to see if you are setting the DataSource/DataMember of the grid after the Hidden property is set. Or check your code to see if you are loading a Layout into the grid (grid.DisplayLayout.LoadXXX).
Hi Mike,
I am trying to use this approach, which seems simple enough, to hide a column during runtime. However in my case I am having no such luck. I have tried setting the .Column["..."].Hidden = false/true,but no luck. I then invoked DataBind() on the grid itself to force the grid to redraw itself, even placing some code inside the InitializeLayout handler, but again no luck. Is it possible to hide or show a column during runtime by using this approach? Or is something more complex required, like destroying the existing grid and recreating?
Thanks,
Matt
You could use an UltraDataSource, as Alex suggests. But there's nothing wrong with a generic list of objects. Just be aware that a List is not a really robust interface and it's not reall intended for data binding. The DotNet BindingManager won't be able to add new items to a List, so you won't be able to use the AddNew row in the grid. Nor will it send notifications to the grid when values in the list change in code - not through the grid. The UltraDataSource would solve all of these problems for you. Another option would be to use a generic BindingList instead of a List.
Either way, you can add unbound columns to the grid usng the add method on the Band. And you can also hide columns using the Hidden property (as Alex mentions above).
One thing I would recommend, though, is that you use the InitializeLayout event for all of this. The event fires any time the grid's DataSource changes, so it's designed to allow you to set up your layout.
Hi, btesch
I think that persons from Infragistics support will provide you with the best advices and samples, but I would try to propose my tips. I usually use an UltraDataSource which can represent an intermediate level between your own datasource like generic lists or any others data storages and GUI control like ultra grid.
Your ultra grid must be linked to UltraDataSource like this:
grid.DataSource = ultraDataSource; // where ultraDataSource is an instance of Infragistics.Win.UltraWinDataSource.UltraDataSource class.
Since we use ultradatasource we can delete, add columns.
For adding columns at runtime use the next code snippet:
dataSource.Band.Columns.Add(string column)
Note that an constructor contains also the signature with type of column.
To delete column:
dataSource.Band.Columns.Remove or dataSource.Band.Columns.RemoveAt.
To temporary hide column on UI you should do the following action on ultra grid column:
grid.DisplayLayout.Bands[0].Columns["YourColumnKey"].Hidden = true;
Since setting that property a column will be hidden until doing an opposite actions that is setting hide to false:
grid.DisplayLayout.Bands[0].Columns["YourColumnKey"].Hidden = false;
Thanks, Alex.
Also I am using the UltraGrid component. Sorry.