HasCell method indicates whether the cell for a column has been allocated yet. UltraGrid allocates cells and cell collections lazily - as they are accessed. This is useful for example if you want to perform an operation on a cell, such as resetting previously set appearance settings, that would only be necessary if the cell has been allocated previously. In such a case you can use this method to find out if the cell has been allocated and only perform the operation if it is. This ensures that the cell doesn't get unnecessarily allocated.
Note that there must be a column with the specified key in the associated band's columns collection otherwise this method will throw an exception. If the intention is to find out if a column with the specified key exists then use the CellCollection's Exists method instead.
Note that for better efficiency you may want to use HasCell overloads that take column index or a column object as they do not require searching the collection for the matching column key.
Imports Infragistics.Shared Imports Infragistics.Win Imports Infragistics.Win.UltraWinGrid Private Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles button1.Click Dim row As UltraGridRow = Me.ultraGrid1.Rows(4) Dim column As UltraGridColumn = row.Band.Columns("CustomerID") ' UltraGrid lazily allocates cells as they are accessed. ' If the cell hasn't been accessed yet, HasCell will return false. Debug.WriteLine("Cell Allocated? " & row.HasCell(column)) ' Accessing the cell will cause the UltraGrid to allocate it. Dim cell As UltraGridCell = row.Cells(column) ' Since we accessed the cell above causing it be allocated, HasCell ' will return true. Debug.WriteLine("Cell Allocated? " & row.HasCell(column)) ' You can cause the grid to release references to cells by calling ' DeallocateCells. This also means that any cell specific settings ' will be cleared. row.DeallocateCells() ' HasCell will return false since we've de-allocated cells. Debug.WriteLine("Cell Allocated? " & row.HasCell(column)) End Sub
using Infragistics.Shared; using Infragistics.Win; using Infragistics.Win.UltraWinGrid; using System.Diagnostics; private void button1_Click(object sender, System.EventArgs e) { UltraGridRow row = this.ultraGrid1.Rows[4]; UltraGridColumn column = row.Band.Columns[ "CustomerID" ]; // UltraGrid lazily allocates cells as they are accessed. // If the cell hasn't been accessed yet, HasCell will return false. Debug.WriteLine( "Cell Allocated? " + row.HasCell( column ) ); // Accessing the cell will cause the UltraGrid to allocate it. UltraGridCell cell = row.Cells[ column ]; // Since we accessed the cell above causing it be allocated, HasCell // will return true. Debug.WriteLine( "Cell Allocated? " + row.HasCell( column ) ); // You can cause the grid to release references to cells by calling // DeallocateCells. This also means that any cell specific settings // will be cleared. row.DeallocateCells( ); // HasCell will return false since we've de-allocated cells. Debug.WriteLine( "Cell Allocated? " + row.HasCell( column ) ); }
Target Platforms: Windows 10, Windows 8.1, Windows 8, Windows 7, Windows Server 2012, Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2