Version

Add(String,String) Method

Adds a new, unbound column to the columns collection.
Syntax
'Declaration
 
Public Overloads Function Add( _
   ByVal key As String, _
   ByVal caption As String _
) As UltraGridColumn
public UltraGridColumn Add( 
   string key,
   string caption
)

Parameters

key
The key of the new column.
caption
The HeaderBase.Caption of the new column.

Return Value

The newly added column.
Example
IsBound indicates whether a column is a bound column or an unbound column. Bound columns are the columns that come from the bound data source. Unbound columns are the columns that you add to the ColumnsCollection returned by Columns property of the UltraGridband. Following sample code shows you how to add an unbound column and then loops through all the columns printing out whether each of the columns is a bound column or unbound column.

Imports Infragistics.Shared
Imports Infragistics.Win
Imports Infragistics.Win.UltraWinGrid
Imports System.Diagnostics

   Private Sub Button14_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles button14.Click

       Dim band As UltraGridBand = Me.UltraGrid1.DisplayLayout.Bands(0)

       ' Check if the column has already been added.
       If Not band.Columns.Exists("UBColumn1") Then
           ' Add an unbound column with the key of "UBColumn1"
           band.Columns.Add("UBColumn1")
           band.Columns("UBColumn1").DataType = GetType(String)
       End If

       ' Loop through all the columns and print out the keys of the columns that are
       ' unbound. There will be only one such column since we've added only one unbound
       ' column above.
       Dim i As Integer
       For i = 0 To band.Columns.Count - 1
           ' IsBound indicates whether a column is a bound column or is an unbound column.
           If Not band.Columns(i).IsBound Then
               Debug.WriteLine(band.Columns(i).Key & " is an unbound column")
           Else
               ' Each bound column has a PropertyDescriptor associated with it. PropertyDescriptor is 
               ' associated with a column or field in the underlying data structure. The UltraGrid
               ' gets property descriptors through BindingManagerBase.GetItemProperties method.
               Dim pd As System.ComponentModel.PropertyDescriptor = band.Columns(i).PropertyDescriptor

               Debug.WriteLine(band.Columns(i).Key & " is a bound column. Property descriptor info: Name = " & pd.Name & ", Type = " & pd.PropertyType.Name)
           End If
       Next

   End Sub
using Infragistics.Shared;
using Infragistics.Win;
using Infragistics.Win.UltraWinGrid;
using System.Diagnostics;

private void button14_Click(object sender, System.EventArgs e)
{

	UltraGridBand band = this.ultraGrid1.DisplayLayout.Bands[0];

	// Check if the column has already been added.
	if ( !band.Columns.Exists( "UBColumn1" ) )
	{	
		// Add an unbound column with the key of "UBColumn1"				
		band.Columns.Add( "UBColumn1" );
		band.Columns["UBColumn1"].DataType = typeof( string );
	}

	// Loop through all the columns and print out the keys of the columns that are
	// unbound. There will be only one such column since we've added only one unbound
	// column above.
	for ( int i = 0; i < band.Columns.Count; i++ )
	{
		// IsBound indicates whether a column is a bound column or is an unbound column.
		if ( !band.Columns[i].IsBound )
		{
			Debug.WriteLine( band.Columns[i].Key + " is an unbound column" );
		}
		else
		{
			// Each bound column has a PropertyDescriptor associated with it. PropertyDescriptor is 
			// associated with a column or field in the underlying data structure. The UltraGrid
			// gets property descriptors through BindingManagerBase.GetItemProperties method.
			System.ComponentModel.PropertyDescriptor pd = band.Columns[i].PropertyDescriptor;

			Debug.WriteLine( band.Columns[i].Key + " is a bound column. Property descriptor info: Name = " + pd.Name + ", Type = " + pd.PropertyType.Name );
		}
	}

}
Requirements

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

See Also