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)
Hi Mike,
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.
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
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.
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
Hello Mike,
I've attached a simple VS2010 VB project which shows the same behavior.