2

我需要将图像设置在网格的单元格内。我有一列是静态创建的,其他列是从数据库动态绑定的。在某些条件和动态值循环的情况下,我必须在静态列的行中设置图像。

//创建的静态列的代码

 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

如何获取静态创建的列的行和单元格并设置图像?

4

1 回答 1

0

由于您的列有一个 ValueList,您可以使用 ValueListItems 的外观来设置图像,然后将ValueList的DisplayStyle设置为Infragistics.Win.ValueListDisplayStyle .Picture 。

例如,您可以使用类似以下 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,因为这将有助于防止内存泄漏。

于 2013-05-13T19:12:27.327 回答