|
|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。如果您注册时有任何问题请联系客服QQ: 83569622 。
您需要 登录 才可以下载或查看,没有帐号?注册
x
UltraWinGrid Cell Appearance
The information in this article applies to:
UltraWinGrid (v1.0.5005)
Summary
When cells need to be embellished with color, images or other unique properties, the UltraWinGrid allows the developer to set Appearance properties for each cell.
Additional Information
Questions
How do I set the background color of all cells with a specific content?
How do I change the default colors for inactive cells?
Can I place a thumbnail image in a cell and not overlap the text?
I would like to place an image in the background of a cell, how do I?
Solutions
When determining the specific properties of any individual cell, the UltraWinGrid looks up through a hierarchy of Appearance objects until it finds a property setting.
At the top of the hierarchy is the Appearance object returned by the CellAppearance property of the Override object that is attached to the DisplayLayout object. (.DisplayLayout.Override.CellAppearance). This Appearance object is used to set cell appearance properties for all cells in all bands. For example, to set the BackColor property of all cells in the grid place the following code in the InitializeLayout event of the UltraWinGrid:
UltraGrid1.DisplayLayout.Override.CellAppearance.BackColor = Color.LightYellow
The next level of the Appearance hierarchy is at the level of the UltraGridBand object. To set the BackColor property for all cells in the grid place the following code in the InitializeLayout event of the UltraWinGrid:
e.Layout.Bands(0).Override.CellAppearance.BackColor = Color.LightGoldenrodYellow
Following the CellAppearance object of the UltraGridBand there is a CellAppearance object for each UltraGridColumn object. Use the following code to set the BackColor of a single column of a band:
e.Layout.Bands(0).Columns(1).CellAppearance.BackColor = Color.LightYellow
There is also a CellAppearance object contained in each row. To se the back color of all cells in a row you can use:
Row.CellAppearance.BackColor = Color.LightYellow
Finally the program can set the Appearance properties of any individual cell. Use the following code to set the BackColor of a single cell inside the InitializeRow event:
e.Row.cells(0).Appearanace.BackColor = Color.LightGreen
Step-By-Step Example
The sample project displays a small table with various CellAppearance properties for the first column and descriptive information in the second column:
This project consists of the following classes and modules:
clsDataTable
clsDataTable exposes a method for creating the a DataTable. This class is not reviewed.
modUtility
modUtility exposes a method used to create an enhanced Application Path. This module is not reviewed.
Form1
Form1 contains the code relevant to this project and consists of the following code regions:
Private Methods
The Private Methods Region contains the following methods:
AddSampleRows - There are a number of sample rows added to the grid with various Appearance Properties:
.BackColor = Color.LightGreen:
UltraGrid1.DisplayLayout.Bands(0).AddNew()
UltraGrid1.ActiveRow.Cells(1).Value = ".BackColor = Color.LightGreen"
With UltraGrid1.ActiveRow.Cells(0).Appearance
.BackColor = Color.LightGreen
End With
.ForeColor = Color.Blue:
UltraGrid1.DisplayLayout.Bands(0).AddNew()
UltraGrid1.ActiveRow.Cells(1).Value = ".ForeColor = Color.Blue"
With UltraGrid1.ActiveRow.Cells(0).Appearance
.ForeColor = Color.Blue
End With
.FontData.Bold = Infragistics.Win.DefaultableBoolean.True:
UltraGrid1.DisplayLayout.Bands(0).AddNew()
UltraGrid1.ActiveRow.Cells(1).Value = ".FontData.Bold = Infragistics.Win.DefaultableBoolean.True"
With UltraGrid1.ActiveRow.Cells(0).Appearance
.FontData.Bold = Infragistics.Win.DefaultableBoolean.True
End With
.Image = anImage:
UltraGrid1.DisplayLayout.Bands(0).AddNew()
UltraGrid1.ActiveRow.Cells(1).Value = ".Image = anImage"
With UltraGrid1.ActiveRow.Cells(0).Appearance
Dim anImage As Image = Image.FromFile(AppPath() + "..\test.jpg").Image = anImage
End With
.ImageBackground = anImage:
UltraGrid1.DisplayLayout.Bands(0).AddNew()
UltraGrid1.ActiveRow.Cells(1).Value = ".ImageBackground = anImage"
With UltraGrid1.ActiveRow.Cells(0).Appearance
Dim anImage As Image = Image.FromFile(AppPath() + "..\test.jpg").ImageBackground = anImage
End With
.TextHAlign = Infragistics.Win.HAlign.Right:
UltraGrid1.DisplayLayout.Bands(0).AddNew()
UltraGrid1.ActiveRow.Cells(1).Value = ".TextHAlign = Infragistics.Win.HAlign.Right"
With UltraGrid1.ActiveRow.Cells(0).Appearance.TextHAlign = Infragistics.Win.HAlign.Right
End With
.BackColorDisabled = Color.LightGray:
UltraGrid1.DisplayLayout.Bands(0).AddNew()
UltraGrid1.ActiveRow.Cells(1).Value = ".BackColorDisabled = Color.LightGray"
UltraGrid1.ActiveRow.Cells(0).Activation = Infragistics.Win.UltraWinGrid.Activation.Disabled
With UltraGrid1.ActiveRow.Cells(0).Appearance
.BackColorDisabled = Color.LightGray
End With
Multiple Property Settings for a Gradient Back Color:
UltraGrid1.DisplayLayout.Bands(0).AddNew()
UltraGrid1.ActiveRow.Cells(1).Value = ".BackGradientStyle = Infragistics.Win.GradientStyle.Horizontal"
With UltraGrid1.ActiveRow.Cells(0).Appearance
.BackColor = Color.Red
.BackColor2 = Color.Blue
.BackGradientStyle = Infragistics.Win.GradientStyle.Horizontal
.ForeColor = Color.White
End With
Form Events
The Form Events Regions contains the following event handlers:
MyBase.Load
When the form loads, create and bind the sample DataTable, add the sample rows and set the UltraGrid ActiveRow to the first row in the grid:
' create DataTable and Bind to Grid
Dim sampleDataMaker As New clsDataTable()
UltraGrid1.DataSource = sampleDataMaker.MakeDataTable
' add sample rows
AddSampleRows()
' set ActiveRow to top row of UltraGrid
UltraGrid1.ActiveRow = UltraGrid1.GetRow(Infragistics.Win.UltraWinGrid.ChildRow.First)
UltraGrid Events
The UltraWinGrid Events Region contains the following event handlers:
UltraGrid1.InitializeLayout
In the InitializeLayout event of the UltraWinGrid: Set the appearance properties of all cells in the grid, override the appearance for a specific band, override for a specific column of a band in the grid, and finally set the proportional width of the columns and ask for AutoFitColumns:
' set Appearance Properties for all Cells in the Grid
e.Layout.Override.CellAppearance.BackColor = Color.LightYellow
' set Appearance Properties for all Cells in a Band of the Grid
e.Layout.Bands(0).Override.CellAppearance.BackColor = Color.LightGoldenrodYellow
' set Appearance Properties for a Column of a Band of the Grid
e.Layout.Bands(0).Columns(1).CellAppearance.BackColor = Color.LightYellow
' Set proportional width and AutoFitColumns
e.Layout.Bands(0).Columns(0).Width = 30
e.Layout.Bands(0).Columns(1).Width = 100
e.Layout.AutoFitColumns = True
UltraGrid1.AfterRowInsert
Set the newly inserted row to the ActiveRow of the grid and populate the value of the first cell:
' Set the ActiveRow to the new row and populate Cell(0)
UltraGrid1.ActiveRow = e.Row
e.Row.Cells(0).Value = "Sample"
Review
This sample project illustrated the hierarchy of overrides and CellAppearance objects used to set default appearance properties for grid cells. It also demonstrates the use of some of the cell appearance properties.
Related Articles
HOWTO: Show multiple images in a cell of the WinGrid (KB06018)
Samples
ultrawingrid_tutorial_cell_appearance.zip
UltraWinGrid Cell Appearance |
|