Jul 202013

The Infragistics WinForm controls are some of the best, most extensible 3rd party controls that I have ever used for UI development.  The set of controls is quite comprehensive and the API is exhaustive.  You can do anything with these controls, in terms of overriding their function and form.  This fact makes using the controls a little intimidating as the gain in extensibility brings with it a high overhead in API knowledge.  Since I use (and tweak) the UltraGrid control most often, I have decided to create a “cheat sheet” post with my most used Infragistics UltraGrid API calls.  Hopefully this will help me (and perhaps someone else) in the future.


//Make column a drop down list style so that the user cannot edit the items in the ValueList
band.Columns["MyColumn"].Style = ColumnStyle.DropDownList;

// Set the ShowExpansionIndicator property to 'CheckOnDisplay' so we don't display
// an expansion indicator for nodes that have no descendants.
band.Override.ExpansionIndicator = ShowExpansionIndicator.CheckOnDisplay;

// Get object bound to row:
return (<MyObject>)row.ListObject;

// Change row to red:
// Do this in grid_InitializeRow
appearance = new Appearance
BackColor = Color.PaleVioletRed,
ForeColor = Color.DarkRed
row.Appearance = appearance;

// Resize columns to fit available area:
// Do this in grid_InitializeLayout
grid.DisplayLayout.AutoFitStyle = AutoFitStyle.ResizeAllColumns;

// Programmatically resize every column as if you had double-clicked the line to the right of the header
// Expands out every column to fit the largest item in the column
foreach (var column in grid.DisplayLayout.Bands[0].Columns)
column.PerformAutoResize(PerformAutoSizeType.VisibleRows, AutoResizeColumnWidthOptions.All);

// Change or localize column headers:
// Do this in grid_InitializeLayout
band.Columns[ColumnName].Header.Caption = “My localized text”;

// Make a column a drop-down list (combo style):
// Do this in grid_InitializeLayout
band.Columns[Status].Style = ColumnStyle.DropDownList;

//Don’t display expansion indicators (+ signs to the left) for nodes in a multi-band grid that have no descendants:
band.Override.ExpansionIndicator = ShowExpansionIndicator.CheckOnDisplay;

// Hide a column across all bands
foreach(var band in diagnosticsInformationGrid.DisplayLayout.Bands)
if (band.Columns.Exists("Tool"))
band.Columns["Tool"].Hidden = true;

// Manually hide/unhide rows by value. In this example, if the status is 0, hide the row.
var allRowsEnumerator = grid.Rows.GetRowEnumerator(GridRowType.DataRow, null, null);
foreach (UltraGridRow row in allRowsEnumerator)
row.Hidden = false;
if (row.Cells["MyStatusColumn"].Value != DBNull.Value)
var compareStatus = (string) row.Cells["MyStatusColumn"].Value;
if (compareStatus == "0") row.Hidden = true;

// Manually remove a column from the column chooser
grid.DisplayLayout.Bands[0].Columns["MyColumn"].ExcludeFromColumnChooser = ExcludeFromColumnChooser.True;

// Hide column headers
grid.DisplayLayout.Bands[0].ColHeadersVisible = false;

// Disable row delete
grid.DisplayLayout.Override.AllowDelete = DefaultableBoolean.False;

// Disable the default grid behavior that allows n splits of the grid into what Infragistics calls "scroll regions"
grid.DisplayLayout.MaxColScrollRegions = 1;
grid.DisplayLayout.MaxRowScrollRegions = 1;

// Disable the activation, and thus edit, of a particular column
grid.DisplayLayout.Bands[0].Columns[0].CellActivation = Activation.NoEdit;

// Add a value list (drop down list) to a grid cell
var editorSettings = new DefaultEditorOwnerSettings();
var valueList = new ValueList();
valueList.ValueListItems.Add(null, null); // Add a blank to allow the user to set the field back to null
foreach (var value in listOfValuesFromSomewhere.ValueList)
valueList.ValueListItems.Add(value.Key, value.Value);
editorSettings.ValueList = valueList;
editorSettings.DataType = typeof(string);
EmbeddableEditorBase editor = new EditorWithCombo(new DefaultEditorOwner(editorSettings));
row.Cells["Value"].Editor = editor;

// Set the grid to NOT make the first row the active row on load. By default, the grid makes the first
// row active, but not selected. It's a bit confusing, so this changes that behavior.
// WARNING - this only works in a read-only grid. Turning of sync will cause issues if you are updating
// grid data.
grid.SyncWithCurrencyManager = false;

// Set up the grid to support IDataErrorInfo
e.Layout.Override.SupportDataErrorInfo = SupportDataErrorInfo.RowsOnly;

e.Layout.Override.DataErrorCellAppearance.ForeColor = Color.DarkRed;
e.Layout.Override.DataErrorRowAppearance.BackColor = Color.MistyRose;
e.Layout.Override.DataErrorRowAppearance.BackColor2 = Color.MistyRose;

e.Layout.Override.RowSelectorWidth = 25; // Make larger to accomodate error icon. Tweak as necessary and make this a const
e.Layout.Override.DefaultRowHeight = 22; // Make larger to accomodate error icon. Tweak as necessary and make this a const

// Sort the grid by some column value
grid.DisplayLayout.Bands[0].Columns["TheColumnOnWhichToSort"].SortIndicator = SortIndicator.Ascending;

// Add a popup menu to a grid //
// Create a new popup menu //
Infragistics.Win.UltraWinToolbars.PopupMenuTool mnuPopupMenu = new Infragistics.Win.UltraWinToolbars.PopupMenuTool("popupMenu");
Infragistics.Win.UltraWinToolbars.ButtonTool btn1 = new Infragistics.Win.UltraWinToolbars.ButtonTool("Button1");
Infragistics.Win.UltraWinToolbars.ButtonTool btn2 = new Infragistics.Win.UltraWinToolbars.ButtonTool("Button2");

// Add the menu and the buttons to the tools collection //

// Add the button tools to the menu //

// Set the caption to be displayed for the button tools //
btn1.SharedProps.Caption = "Button 1"; // Localized string
btn2.SharedProps.Caption = "Button 2"; // Localized string

// Add images to each button on the menu //
btn1.SharedProps.AppearancesSmall.Appearance.Image = imgToolbarImages.Images[0];
btn2.SharedProps.AppearancesSmall.Appearance.Image = imgToolbarImages.Images[1];
// Do large as well //

// Set the context menu for the TextBox control to the popup menu tool created //
ultraToolbarsManager1.SetContextMenuUltra(this.theGrid , "popupMenu");