-
Resize all columns to fit in the available space.
With WinListView selected in design view, go to the properties window and locate the ViewSettingsDetails object. Expand that object and locate the AutoFitColumns property; set it to ResizeAllColumns. Setting AutoFitColumns to ResizeAllColumns will cause all columns, main and sub items, to resize until they all fit in the allotted space.
-
Resize a single column in the MouseMove event .
Create a MouseMove event for the WinListView control. In the MouseMove event, you will find which SubItem the mouse is over by calling the SubItemFromPoint method; just pass in the x- and y-coordinates of the event args. Next, check to make sure the SubItem isn’t null. If the SubItem isn’t null, perform a resize of the SubItem’s column by calling PerformAutoResize off the SubItemColumn in the SubItemColumns collection that matches the Column of the SubItem. Each SubItem has a Column property to make it easy to find its associated SubItemColumn.
Private Sub UltraListView1_MouseMove(ByVal sender As System.Object, _
ByVal e As System.Windows.Forms.MouseEventArgs) _
Handles UltraListView1.MouseMove
' Create a reference to the sub item under the mouse cursor.
Dim subItem As UltraListViewSubItem = _
Me.UltraListView1.SubItemFromPoint(New Point(e.X, e.Y))
' make sure the mouse was over a valid sub item.
If subItem IsNot Nothing Then
' Resize the sub item's column so that all items (visible
' and not visible) and the header fit in the column.
Me.UltraListView1.SubItemColumns(subItem.Column.Index). _
PerformAutoResize(Infragistics.Win.UltraWinListView.ColumnAutoSizeMode.AllItemsAndHeader)
End If
End Sub
private void ultraListView1_MouseMove(object sender, MouseEventArgs e)
{
// Create a reference to the sub item under the mouse cursor.
UltraListViewSubItem subItem =
this.ultraListView1.SubItemFromPoint(new Point(e.X, e.Y));
// make sure the mouse was over a valid sub item.
if (subItem != null)
{
// Resize the sub item's column so that all items (visible
// and not visible) and the header fit in the column.
this.ultraListView1.SubItemColumns[subItem.Column.Index].
PerformAutoResize(Infragistics.Win.UltraWinListView.ColumnAutoSizeMode.AllItemsAndHeader);
}
}
If your WinListView control is filled with data, shrink the window so that some columns can’t display all their contents. Hover over one of the SubItemColumns; you will see it resize as you mouse over it. Notice that the columns automatically go back to their default sizes when you mouse out of the column. This is because AutoFitColumns is automatically resizing the columns continuously. However, when you call PerformAutoResize, That one column’s sizing takes precedence over the other columns.