I want to resize the columns based on the cells' text in all the rows. The grid's data source is set to a BindingSource. After setting the BindingSource's DataSource property to a list of entities, I want to resize the columns in the grid after it finished loading the data.
Is there any event that announces that? Or is there any event that tells me that the visible rows finished loading from the data source?
Thanks.
Hi,
DataBinding is an ongoing process, so it's never "finished". So no, there is no event for this.
But you don't need one. You can just do this:
private void ultraGrid1_InitializeLayout(object sender, Infragistics.Win.UltraWinGrid.InitializeLayoutEventArgs e) { UltraGridLayout layout = e.Layout; layout.PerformAutoResizeColumns(false, PerformAutoSizeType.AllRowsInBand); }
Sorry for the late response, but I needed a little time to play with it.
It partialy works, but I need more:
- auto resize columns on data source changed: InitializeLayout is not raised
- auto resize columns on filtered rows: the auto resize is applied on filtered out rows also
- the column headers are set to word wrap: if the columns are resized based only on cell text, I get a character wrap on number columns. I would like it to resize to a minimum width in which the header caption is readable
- I tried using PerformAutoSizeType.VisibleRows, but I need an event that tells me that the visible rows collection changed. I found the AfterRowRegionScroll for the WinGrid, but I could not found an equivalent for WinCombo
- Trying to resize the columns manually is cumbersome because I could not find an event that tells me when the data was loaded in the visible rows and when the visible rows collection changed.
I am still looking for a solution for this.
Thanks for your support,
Emanuel
I am using PerformAutoResizeColumns and works fine. It doesn't have all the features I would like, but it works.
Hi Emanuel,
AutoSizing the columns is done via a method, so it happens once. It's not a continuous process.
There are two problems with what you are trying to do:
First, if you pass the grid/combo to a method and you want to hook an event so you will know when the autosize the columns, there is no one event that you could use. You would have to use a multitude of events to track every possible case where the width might need to change.
For the combo, I suppose you could use the DropDown event and that would probably work very well, since it's unlikely that the contents of the Combo will change while it is dropped down - except for filtering.
The second issue is the filtering. As I explained in my previous post, there is no method in the grid that will autosize only the unfiltered rows without regard to whether or not they are scrolled into view.
A typical application will autosize all of the columns in the InitializeLayout event so they appear correct initially, and if the user makes changes or needs to update the auto-sizing after that, they need to double-click on the right edge of the column header.
Hi Mike,
I think I have lost myself in details. Here is what I want to achieve:
In the app I develop there are a lot of lists that are displayed in grids and entities that depend on other entities, which are displayed in combos.
In the grids, when the data is refreshed or a filter is applied on it I would like to resize the columns with the new data.
In the combos, which are filtered programatically (UltraGridRow.Hidden = true), I would like to resize the columns of the remaining rows, so that all the text is visible when the user drops down the combo's list.
In both cases I would like to also hide the columns that are empty (GetText method returns null or empty string).
To implement the functionality described above I have created an object which receives a reference to the grid or the combo, has a list of columns that should be visible in every band. I am looking for a way to be able to respond to event and resize the must be visible columns, and hide the empty ones.
Thanks,
ehaisiuc said:- auto resize columns on data source changed: InitializeLayout is not raised
I don't know what you mean by this. If you set the DataSource or DataMember property on the grid, then the InitializeLayout event will fire. If you are talking about other data source changes, like the change of a value in the field, then you are correct, the InitializeLayout event will not fire. But you would have to track those changes and call PerformAutoResize on the column from some other place in the code.
ehaisiuc said:- auto resize columns on filtered rows: the auto resize is applied on filtered out rows also
The PerformAutoResize method has many overloads and many options. You can limit it to VisibleRows instead of AllRowsInBand. But note that VisibleRows means rows that are visible on the screen. It excludes filtered-out rows, but it also excludes rows that are scrolled out of view. There is no option to exclude just hidden rows without also excluded rows scrolled out of view.
ehaisiuc said:- the column headers are set to word wrap: if the columns are resized based only on cell text, I get a character wrap on number columns. I would like it to resize to a minimum width in which the header caption is readable
There are overloads of PerformAutoResize that let you specify whether to include the column header or not. There is also a CalculateAutoSizeWidth method on the column which is the same as PerformAutoResize, except that it just returns the size, it doesn't apply it to the column. So you could get the width and then apply a minimum if the returned width is lower.
ehaisiuc said:- I tried using PerformAutoSizeType.VisibleRows, but I need an event that tells me that the visible rows collection changed. I found the AfterRowRegionScroll for the WinGrid, but I could not found an equivalent for WinCombo
There is no single event for this. It seems like you are trying to autosize the column any time anything changes so that you are constantly keeping the width autosize at all times. This probably isn't realistic. I know of no application that does this.