【问题标题】:Is there a way to change the background of a single cell in ultragrid?有没有办法改变超网格中单个单元格的背景?
【发布时间】:2021-12-08 00:14:22
【问题描述】:

我查看了官方基础设施网站和多个论坛,但它改变了整行或列的背景颜色。 这是我想要实现的一些伪代码:

If cellValue != 0 or  cellValue Isnot nothing

    change background color of cellValue to yellow

你知道怎么做吗? 我感谢任何帮助,在 vb.net 或 c# 中首选

【问题讨论】:

    标签: c# vb.net winforms infragistics


    【解决方案1】:
    If e.Row.Cells("CELL_NAME").Text <> 0 Then
            e.Row.Appearance.BackColor = Color.Red   'change row's color
            e.Row.Cells("CELL_NAME").Appearance.BackColor = Color.Red    'change cell's color
    End If
    

    此代码适用于 InitializeRows 事件。 您在此事件中编写的代码将在网格的所有行上执行。

    【讨论】:

    • 你能发布你的代码吗?
    • Select Case result.Status Case Status.Modified Dim cell As UltraGridCell = Me.ugResult.Rows(1).Cells(1) e.Row.Cells(cell).Appearance.BackColor = Color.Yellow End Select
    • 我发布的代码,您必须放入“InitializeRow Event”中。像这样: Private Sub ugResult_InitializeRow(ByVal sender As Object, ByVal e As Infragistics.Win.UltraWinGrid.InitializeRowEventArgs) 处理 ugResult.InitializeRow [然后发布我发布的代码]。试试这个。
    • “CELL_NAME”应该做什么?我没有具体的单元格名称。我必须遍历网格,如果在“价格”列中,例如单元格值不是 0 也不是什么都不是,那么单元格应该是彩色的。
    【解决方案2】:

    在 Marco 的帮助下找到了解决方案。我的目标是更改特定列中的单元格颜色,如果它们的值不为 0。您需要在 InitalizeRow 事件中执行此操作。这是我所做的:

    For Each column As UltraGridColumn In ugResult.DisplayLayout.Bands(0).Columns
                    If column.ToString = "K_Art" Or column.ToString = "UANR" Or column.ToString = "Ueberbegriff" Or column.ToString = "Benennung" Or column.ToString = "Anzahl" Or column.ToString = "Einheit" Or column.ToString = "Einzelkosten" Or column.ToString = "Sumcode" Or column.ToString = "Status" Then
                        Exit For
                    Else
                        For Each r As UltraGridRow In ugResult.Rows
                            If r.Cells(column.Index).Value <> 0 Then
                                r.Cells(column.Index).Appearance.BackColor = Color.Yellow
                            End If
    
                        Next
                    End If
                Next
    

    【讨论】:

      猜你喜欢
      • 2015-07-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-08-02
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多