简体   繁体   English

在VB.net中的UltraGrid中更改特定OutlookGroupBy组中的行颜色

[英]change row colors in a specific OutlookGroupBy group in UltraGrid in VB.net

I am using an ultragrid and inside i have values that i load into a datatable from a database. 我正在使用ultragrid,而且我有从数据库加载到数据表中的值。 In my grid i group the rows into groups with OutlookGroupBy code. 在我的网格中,我使用OutlookGroupBy代码将行分组。 My rows in the grid are in two categories. 我在网格中的行分为两类。 The Priority 1 and 0. I want when the data are loaded the rows that are in priority 1 to get color red, and the others in priority 0 to be in normal color. 优先级1和0.我希望在数据加载时,优先级为1的行为红色,优先级为0的其他行为正常颜色。

I use the ultragrid pro grammatically so i didnt use any of its features in the editor. 我以编程方式使用ultragrid,所以我没有在编辑器中使用它的任何功能。

here is how i initialize my grid and how i load from database from another class: 这是我如何初始化我的网格以及如何从另一个类从数据库加载:

 Dim dt As DataTable = Nothing

        Timer1.Enabled = True
        UltraGrid1.DataSource = Nothing
        Generic.openOrders(dt)
        UltraGrid1.DataSource = dt

        Dim band As Infragistics.Win.UltraWinGrid.UltraGridBand = UltraGrid1.DisplayLayout.Bands(0)
        UltraGrid1.DisplayLayout.ViewStyleBand = Infragistics.Win.UltraWinGrid.ViewStyleBand.OutlookGroupBy
        band.SortedColumns.Add(band.Columns("PRIORITY"), True, True)
        band.SortedColumns.Add(band.Columns("ORDERID"), False, True)
        band.SortedColumns.Add(band.Columns("ORDERTIME"), False, True)

anyone has any idea of how can i change the row color into the priority 1 subrows?? 任何人都知道如何将行颜色更改为优先级1子行?

You can try with this approach: 您可以尝试这种方法:

First you need to subscribe the event InitializeRow , so add this by the designer or by code (eg. in Form_Load or before setting the DataSource of the grid) 首先,您需要订阅事件InitializeRow ,因此请由设计人员或代码添加(例如,在Form_Load中或在设置网格的DataSource之前)

grd.InitializeRow += new InitializeRowEventHandler(grd_InitializeRow);

then, in the event, write code like this 然后,在这种情况下,写这样的代码

private void grd_InitializeRow(object sender, InitializeRowEventArgs e)
{
    if(e.Row.Band.Index == 1)
    {
         if(Convert.ToInt32(e.Row.Cells["PRIORITY"].Value) == 1)
              e.Row.Appearance.BackColor = Color.LightGreen;
    }
}

Keep in mind that if you have set CellAppearance they will have precedence on RowAppearance and, if you have many rows it is better to initialize an Appearance object, store it in the grid.DisplayLayout.Appearances collection and reuse the same object for every row involved. 请记住,如果您设置了CellAppearance它们将优先于RowAppearance ,如果您有很多行,最好初始化Appearance对象,将其存储在grid.DisplayLayout.Appearances集合中,并为每个涉及的行重用相同的对象。

Moreover, always with the aim of improving the performance, to get the cell value it is better to use the GetCellValue method of the row. 此外,为了提高性能,要获得单元格值,最好使用行的GetCellValue方法。 This will avoid the creation of the a full Cell object just to retrieve its value. 这将避免创建完整的Cell对象以获取其值。 Things are a bit more complicated because you need an UltraGridColumn and not just the name of the column, but in the InitializeRow event, fired for each row, this is little price to pay. 事情有点复杂,因为你需要一个UltraGridColumn而不仅仅是列的名称,但是在InitializeRow事件中,为每一行触发,这是付出的代价。

private void grd_InitializeRow(object sender, InitializeRowEventArgs e)
{
    if(e.Row.Band.Index == 1)
    {
         UltraGridColumn priorityColumn = e.Row.Band.Columns["PRIORITY"];
         if(Convert.ToInt32(e.Row.GetCellValue(priorityColumn)) == 1)
              e.Row.Appearance.BackColor = Color.LightGreen;
    }
}

EDIT: The same code in VB.NET 编辑: VB.NET中的相同代码

....
AddHandler grd.InitializeRow, AddressOf Me.grd_InitializeRow
....


Private Sub grd_InitializeRow(sender As System.Object, e As InitializeRowEventArgs)
    If e.Row.Band.Index = 1 Then
        Dim priorityCol As UltraGridColumn = e.Row.Band.Columns("PRIORITY")
        If Convert.ToInt32(e.Row.GetCellValue(priorityCol)) = 1 Then
            e.Row.Appearance.BackColor = Color.LightGreen
        End If
    End If
End Sub

Also, the use the UltraGridColumn class, you need to add at the start of file 另外,使用UltraGridColumn类,需要在文件的开头添加

Imports Infragistics.Win.UltraWinGrid

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM