Hi,
I'm using the following code in the wingrid initializeLayout event to autosize the columns:
gridASD.DisplayLayout.Override.AllowColSizing = AllowColSizing.Free
gridASD.DisplayLayout.PerformAutoResizeColumns(True, Infragistics.Win.UltraWinGrid.PerformAutoSizeType.VisibleRows, True)
This code does not look like it will work for any column. My guess is that all of your columns are being sorted only by the column header.
The problem is that you are specifying VisibleRows and when InitializeLayout fires, there will probably be none. I recommend using AllRows or specifying a number of rows like 10 or 20 (enough to fill the visible area).
Another potential problem is that you might be calling this code before the ValueList is attached to the column or before the ValueList is populated with data.
Hi Mike,
To give you more background in the order in which things are happening,:
I've tried specifying allrows as well as visiblerows but the result is the same. Also the other non value list columns are resizing to the contents of the cell rather than only the column header, where the cell contents is larger (I'm assuming you meant resized rather than sorted in your first paragraph) .
Once the grid has drawn, if I manually double click on the column header divider of a column with a value list, it does resize to show the full text description.
Thanks,
Darren
Hello Mike,
I've attached a simple VS2010 VB project which shows the same behavior.
As a work around have you tried the Shown event of the Form? When I tested the work around on the sample you created it worked perfectly.
Private Sub Form1_Shown(sender As Object, e As System.EventArgs) Handles Me.Shown UltraGrid1.DisplayLayout.Override.AllowColSizing = AllowColSizing.Free UltraGrid1.DisplayLayout.PerformAutoResizeColumns(True, Infragistics.Win.UltraWinGrid.PerformAutoSizeType.AllRowsInBand, True) End Sub
Thanks Torrey,
The problem is that once the form is shown on my full application, the user will be selecting an item from a list which will result in the grid being bound to a different datasource and redrawn without the form itself being affected.
Your code assumed that the Form_Load fires before the InitializeLayout. But it does not. So you are Auto-Sizing the columns before the ValueList is attached to the column.
Move your code from Form_Load into InitializeLayout. That's a better place to attach the ValueList, anyway.
You should also use e.Layout instead of UltraGrid1.DisplayLayout. And I recommend giving your ValueList a key if you are adding it to the ValueLists collection on the grid. Here's how I would do it:
Private Sub UltraGrid1_InitializeLayout(sender As Object, e As Infragistics.Win.UltraWinGrid.InitializeLayoutEventArgs) Handles UltraGrid1.InitializeLayout Dim theValueList As ValueList If Not e.Layout.ValueLists.Exists("MyValueList") Then theValueList = e.Layout.ValueLists.Add("MyValueList") theValueList.ValueListItems.Add(1, "VALUE LIST ITEM 1") theValueList.ValueListItems.Add(2, "VALUE LIST ITEM 2") Else theValueList = e.Layout.ValueLists("MyValueLits") End If e.Layout.Bands(0).Columns("MyValueList").ValueList = theValueList e.Layout.Override.AllowColSizing = AllowColSizing.Free e.Layout.PerformAutoResizeColumns(True, Infragistics.Win.UltraWinGrid.PerformAutoSizeType.AllRowsInBand, True) End Sub
The sample project I attached was just a simple example and not how my actual application is structured, but I appreciate the tips, and as soon as I checked when the InitializeLayout event was firing, I can see that it occurs as soon as the grid is bound to the datasource, which does occur before the valuelists are attached in my app, so many thanks.