vb.net 在 Infragistics 网格的单元格中设置图像
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/16355480/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Set image in a cell of Infragistics grid
提问by
I need to set the image inside a cell of my grid. I have a column which is created in static and the other columns are bounded dynamically from database. With a certain conditions and looping of the dynamic values i have to set a image in the row of the static column.
我需要在网格的单元格内设置图像。我有一个以静态方式创建的列,其他列是从数据库动态限定的。在特定条件和动态值循环的情况下,我必须在静态列的行中设置图像。
//Code of static column created
//创建静态列的代码
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
//Code to set the image
//设置图片的代码
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
How to get the row and cell of the column created statically and set the image?
如何获取静态创建的列的行和单元格并设置图像?
回答by alhalama
Since your column has a ValueList you can use the Appearance of the ValueListItems to set the image and then set the DisplayStyleof the ValueList to be Infragistics.Win.ValueListDisplayStyle.Picture.
由于您的列有一个 ValueList,您可以使用 ValueListItems 的 Appearance 来设置图像,然后将ValueList的DisplayStyle设置为Infragistics.Win.ValueListDisplayStyle.Picture 。
For example you could use something like the following C# example:
例如,您可以使用类似于以下 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;
}
Note that this will limit the number of image objects that are created if you are using the same image multiple times for multiple rows. This example also uses an image list so that Dispose will be called on the images as this will help prevent memory leaks.
请注意,如果您为多行多次使用相同的图像,这将限制创建的图像对象的数量。此示例还使用图像列表,以便对图像调用 Dispose,因为这将有助于防止内存泄漏。

