Determining the width in any arbitrary case is extremely difficult, because the grid has so many options. Multiple bands, RowLayouts, overlapping borders, scrollbars, card view, etc.
In the simplest case with a single band, the GetExtent method on the band should get you most of the way there. If it's not working for you, then my guess is that it's a problem with timing. The grid does a lot of metrics calculations asynchronously, so you need to make sure the grid paints so that all calculations are performed before you try to use GetExtent or other measurements.
Then you just have to account for Scrollbars and borders which can be done via the UIElements.
private void AutoSizeGridToContents(Infragistics.Win.UltraWinGrid.UltraGrid ultraGrid)
{
UltraGridLayout layout = ultraGrid.DisplayLayout;
UltraGridBand rootBand = layout.Bands[0];
int extent = rootBand.GetExtent(BandOrigin.PreRowArea);
UIElement gridElement = layout.UIElement;
UIElementBorderStyle borderStyle = gridElement.BorderStyle;
Border3DSide borderSides = gridElement.BorderSides;
UIElementBorderWidths borderWidths = DrawUtility.CalculateBorderWidths(borderStyle, borderSides, gridElement);
extent += borderWidths.Left + borderWidths.Right;
UIElement scrollbarUIElement = gridElement.GetDescendant(typeof(RowScrollbarUIElement));
if (null != scrollbarUIElement)
extent += scrollbarUIElement.Rect.Width;
ultraGrid.Width = extent;
}
Like I said, this works in the simplest case with just a single band.