我需要在网格的单元格内设置图像。我有一个在静态创建的列,其他列是从数据库动态绑定的。在某些条件和循环动态值的情况下,我必须在静态列的行中设置图像。
//创建静态列代码
If UltraGridColumn.Tag Is Nothing And UltraGridColumn.Key = "TransactionStatus" Then
'Configure column
UltraGridColumn.CellActivation = If(Me.WorkflowsController.SelectedWorkflow.HasUpdateAccess, Activation.AllowEdit, Activation.ActivateOnly)
UltraGridColumn.CellAppearance.BackColor = Color.LightYellow
UltraGridColumn.CellAppearance.FontData.Bold = If(Me.WorkflowsController.SelectedWorkflow.HasUpdateAccess, DefaultableBoolean.True, DefaultableBoolean.False)
UltraGridColumn.CellAppearance.FontData.Italic = If(Not Me.WorkflowsController.SelectedWorkflow.HasUpdateAccess, DefaultableBoolean.True, DefaultableBoolean.False)
UltraGridColumn.ExcludeFromColumnChooser = ExcludeFromColumnChooser.True
UltraGridColumn.Header.Caption = "Transaction Status"
UltraGridColumn.Header.ToolTipText = "Transaction status."
UltraGridColumn.Hidden = False
UltraGridColumn.Style = ColumnStyle.DropDownList
UltraGridColumn.ValueList = Me.WorkflowsController.StatusesController.StatusesValueList
End If
//设置图片的代码
Dim transId = TransactionCommentsCollection.Select(Function(x) x.TransactionId)
Dim transLevelId = transId.Intersect(TransactionLevelCommentsCollection.Select(Function(x) x.TransactionId))
If (transLevelId.Contains(Record.TransactionId)) Then
//Get the corresponding cell here
'Set the cell image
UltraGridCell.Appearance.Image = My.Resources.Tran_comment_16
UltraGridCell.Appearance.ImageHAlign = HAlign.Right
UltraGridCell.Appearance.ImageVAlign = VAlign.Top
End If
如何静态创建列的行和单元格并设置图像?
答案 0 :(得分:0)
由于您的列具有ValueList,您可以使用ValueListItems的Appearance设置图像,然后将ValueList的DisplayStyle设置为Infragistics.Win.ValueListDisplayStyle。图片。
例如,你可以使用类似下面的C#示例:
void ultraGrid1_InitializeLayout(object sender, Infragistics.Win.UltraWinGrid.InitializeLayoutEventArgs e)
{
// The column ("Department") in the grid will display a ValueList
// with sample images. The values in this column will be
// from 0 to 3.
// Create a ValueList with three items, one for each color
// of the traffic light.
Infragistics.Win.ValueList vl = this.GetDepartmentsValueList();
vl.DisplayStyle = Infragistics.Win.ValueListDisplayStyle.Picture;
for (int i = 0; i < 4; i++)
{
vl.ValueListItems[i].Appearance.Image = this.imageList1.Images[i];
}
// Attach this ValueList to the "Department" column in the grid.
e.Layout.Bands[0].Columns["Department"].ValueList = vl;
}
private Infragistics.Win.ValueList GetDepartmentsValueList()
{
Infragistics.Win.ValueList vl = new Infragistics.Win.ValueList();
for (int i = 0; i < 4; i++)
{
vl.ValueListItems.Add(i, string.Format("Department {0}", i) );
}
return vl;
}
请注意,如果多次使用同一图像多次,则会限制创建的图像对象的数量。此示例还使用图像列表,以便在图像上调用Dispose,因为这有助于防止内存泄漏。