Gets/sets the view style for the control, i.e., whether columns are displayed and if so, how they are displayed.
Syntax
| Visual Basic (Declaration) | |
|---|
Public Property ViewStyle As ViewStyle |
Example
The following code sample demonstrates how to use the properties of the UltraTreeNodeColumn object to modify the behavior and appearance of the cells displayed by the column.
| Visual Basic | Copy Code |
|---|
Imports Infragistics.Win
Imports Infragistics.Win.Layout
Imports Infragistics.Win.UltraWinTree
Private Sub button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles button1.Click
Dim dataTable As DataTable = Me.GetData()
Me.ultraTree1.ViewStyle = ViewStyle.Grid
Dim rootColumnSet As UltraTreeColumnSet = Me.ultraTree1.ColumnSettings.RootColumnSet
Dim dataColumn As DataColumn
For Each dataColumn In dataTable.Columns
Dim column As UltraTreeNodeColumn = rootColumnSet.Columns.Add(dataColumn.ColumnName)
column.Tag = dataColumn
column.AllowMoving = GridBagLayoutAllowMoving.AllowAll
column.AllowSorting = DefaultableBoolean.True
column.AutoSizeMode = ColumnAutoSizeMode.VisibleNodes
If dataColumn.DataType Is GetType(String) Then
column.CanShowExpansionIndicator = DefaultableBoolean.True
Else
column.CanShowExpansionIndicator = DefaultableBoolean.False
End If
If column.Key = "CompanyName" Then
column.CellAppearance.BackColor = Color.LightBlue
column.CellAppearance.BackColor2 = Color.CornflowerBlue
column.CellAppearance.BackGradientStyle = GradientStyle.Horizontal
column.CellAppearance.ForeColor = Color.DarkBlue
End If
column.CellWrapText = DefaultableBoolean.False
column.DataType = dataColumn.DataType
column.Editor = New EditorWithText()
If column.Key = "RecordID" Then
column.Format = "00000"
End If
column.FormatProvider = System.Globalization.CultureInfo.CurrentCulture
column.HeaderAppearance.ForeColor = SystemColors.ControlDark
column.NullText = "[NULL]"
column.ShowSortIndicators = DefaultableBoolean.True
If column.Key = "CompanyName" Then
column.SortType = SortType.Ascending
End If
If column.Key = "CompanyName" Then
column.Text = "Company Name"
End If
Next
rootColumnSet.Columns("CustomerID").Visible = False
Dim row As DataRow
For Each row In dataTable.Rows
Dim nodeKey As String = row("CustomerID")
Dim node As UltraTreeNode = Me.ultraTree1.Nodes.Add(nodeKey)
For Each dataColumn In dataTable.Columns
Dim val As Object = row(dataColumn.ColumnName)
node.SetCellValue(rootColumnSet.Columns(dataColumn.ColumnName), val)
Next
Next
End Sub
Private Function GetData() As DataTable
Dim dataTable As DataTable = New DataTable()
dataTable.Columns.Add("RecordID", GetType(Integer))
dataTable.Columns.Add("CustomerID", GetType(String))
dataTable.Columns.Add("CompanyName", GetType(String))
dataTable.Columns.Add("ContactName", GetType(String))
dataTable.Columns.Add("ContactTitle", GetType(String))
dataTable.Rows.Add(New Object() {1652, "ALFKI", "Alfreds Futterkiste", "Maria Anders", "Sales Representative"})
dataTable.Rows.Add(New Object() {1346, "ANATR", "Ana Trujillo Emparedados y helados", "Ana Trujillo", "Owner"})
dataTable.Rows.Add(New Object() {127, "ANTON", "Antonio Moreno Taquería", "Antonio Moreno", "Owner"})
dataTable.Rows.Add(New Object() {4460, "AROUT", "Around the Horn", "Thomas Hardy", "Sales Representative"})
dataTable.Rows.Add(New Object() {166, "BERGS", "Berglunds snabbköp", "Christina Berglund", "Order Administrator"})
Return dataTable
End Function
|
| C# | Copy Code |
|---|
using Infragistics.Win; using Infragistics.Win.Layout; using Infragistics.Win.UltraWinTree; using System.Diagnostics;
private void button1_Click(object sender, System.EventArgs e)
{
DataTable dataTable = this.GetData();
// Set the ViewStyle property to 'Grid'
this.ultraTree1.ViewStyle =
ViewStyle.Grid;
// Add a column for each DataColumn in the
DataTable to the RootColumnSet's
// Columns collection, using the DataColumn's
'ColumnName' property as the
// key for the corresponding
UltraTreeNodeColumn.
UltraTreeColumnSet rootColumnSet = this.ultraTree1.ColumnSettings.RootColumnSet;
foreach( DataColumn dataColumn
in dataTable.Columns )
{
UltraTreeNodeColumn column = rootColumnSet.Columns.Add(
dataColumn.ColumnName );
// Store a reference to
the underlying DataColumn in the Tag property.
column.Tag = dataColumn;
// Set AllowMoving to
'AllowAll', so that the end user
// can drag the column
to a different location.
column.AllowMoving =
GridBagLayoutAllowMoving.AllowAll;
// Set AllowSorting to
True, so that the end user
// can sort the nodes
collections associated with
// this column by
clicking on its header.
column.AllowSorting =
DefaultableBoolean.True;
// Set AutoSizeMode to
'VisibleNodes', so that the end user
// can auto-size the
column by double-clicking on the right
// edge of its
header.
column.AutoSizeMode =
ColumnAutoSizeMode.VisibleNodes;
// Set
CanShowExpansionIndicator to True for the string columns,
// so that cells in the
column can show the expansion indicator
// when the ViewStyle is
'OutlookExpress'.
if (
dataColumn.DataType == typeof(string) )
column.CanShowExpansionIndicator =
DefaultableBoolean.True;
else
column.CanShowExpansionIndicator = DefaultableBoolean.False;
// Use the column's
CellAppearance to change the color of
// the text displayed by
the cells in the 'CompanyName' column.
if ( column.Key
== "CompanyName" )
{
column.CellAppearance.BackColor =
Color.LightBlue;
column.CellAppearance.BackColor2 =
Color.CornflowerBlue;
column.CellAppearance.BackGradientStyle =
GradientStyle.Horizontal;
column.CellAppearance.ForeColor =
Color.DarkBlue;
}
// Set CellWrapText to
False to prevent text from
// wrapping to
additional lines.
column.CellWrapText =
DefaultableBoolean.False;
// Set the DataType
property to the DataType of the associated DataColumn
column.DataType = dataColumn.DataType;
// Use an EditorWithText
embeddable editor to render the cell data
column.Editor = new EditorWithText();
// Format the 'RecordID'
column
if ( column.Key
== "RecordID" )
column.Format = "00000";
// Assign the current
culture to the FormatProvider property.
column.FormatProvider =
System.Globalization.CultureInfo.CurrentCulture;
// Set the ForeColor
property of the HeaderAppearance
column.HeaderAppearance.ForeColor =
SystemColors.ControlDark;
// Set the NullText
property to "[NULL]"
column.NullText = "[NULL]";
// Show sort indicators
for all columns
column.ShowSortIndicators =
DefaultableBoolean.True;
// Sort the
'CompanyName' column in ascending order
if ( column.Key
== "CompanyName" )
column.SortType = SortType.Ascending;
// Set the Text property
of the 'CompanyName' column
if ( column.Key
== "CompanyName" )
column.Text = "Company Name";
}
// Hide the 'CustomerID' column
rootColumnSet.Columns["CustomerID"].Visible = false;
// Add a node for each DataRow in the table
foreach( DataRow row in dataTable.Rows )
{
string nodeKey =
row["CustomerID"] as string;
UltraTreeNode node = this.ultraTree1.Nodes.Add( nodeKey );
foreach(
DataColumn dataColumn in dataTable.Columns )
{
object
val = row[dataColumn.ColumnName];
node.SetCellValue(
rootColumnSet.Columns[dataColumn.ColumnName], val );
}
}
}
private DataTable GetData()
{
// Create a DataTable
DataTable dataTable = new
DataTable();
// Add some columns
dataTable.Columns.Add( "RecordID", typeof(int) );
dataTable.Columns.Add( "CustomerID", typeof(string) );
dataTable.Columns.Add( "CompanyName", typeof(string) );
dataTable.Columns.Add( "ContactName", typeof(string) );
dataTable.Columns.Add( "ContactTitle", typeof(string) );
// Add some rows
dataTable.Rows.Add( new
object[]{ 1652, "ALFKI", "Alfreds Futterkiste", "Maria Anders", "Sales Representative" } );
dataTable.Rows.Add( new object[]{ 1346, "ANATR", "Ana Trujillo
Emparedados y helados", "Ana Trujillo", "Owner"
} );
dataTable.Rows.Add( new object[]{ 127, "ANTON", "Antonio Moreno
Taquerí, "Antonio Moreno", "Owner" }
);
dataTable.Rows.Add( new object[]{ 4460, "AROUT", "Around the
Horn", "Thomas Hardy", "Sales Representative"
} );
dataTable.Rows.Add( new object[]{ 166, "BERGS", "Berglunds
snabbkö, "Christina Berglund", "Order
Administrator" } );
return dataTable;
}
|
See Also