Results 1 to 3 of 3

Thread: [RESOLVED] Color grouping datagridview rows

  1. #1

    Thread Starter
    PowerPoster make me rain's Avatar
    Join Date
    Sep 2008
    Location
    india/Hubli
    Posts
    2,208

    Resolved [RESOLVED] Color grouping datagridview rows

    i need to group the rows of a datagridview rows basing on values in column1
    of DGV.

    i mean for example while loop
    if .Rows(TOPROW).Cells(0).Value =
    .Rows(NextRow).Cells(0).Value then
    color the rows with some unique color
    else
    color them differently

    some peace of code pl
    The averted nuclear war
    My notes:

    PrOtect your PC. MSDN Functions .OOP LINUX forum
    .LINQ LINQ videous
    If some one helps you please rate them with out fail , forum doesn't expects any thing other than this

  2. #2
    Karen Payne MVP kareninstructor's Avatar
    Join Date
    Jun 2008
    Location
    Oregon
    Posts
    6,714

    Re: Color grouping datagridview rows

    Look at the following example
    http://www.vbforums.com/showpost.php...66&postcount=6

    In this example code taken from the project link above if a column named column1 has a length of 4 it gets a new font. Then for you to do the background colors add in your logic in InvokeBanding or ConditionsBandingPrep. Here it is shown in InvokeBanding.

    Code:
    Module DataGridViewExtensions
        Private ConditionalFont As Font = New System.Drawing.Font("Microsoft Sans Serif", 8.25!, _
                System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        <System.Diagnostics.DebuggerStepThrough()> _
        <Runtime.CompilerServices.Extension()> _
       Public Sub InvokeBanding(ByVal sender As Windows.Forms.DataGridView)
            For Each band As DataGridViewBand In sender.Rows
                If band.Tag IsNot Nothing Then
                    band.DefaultCellStyle.Font = CType(band.Tag, Font)
                    band.DefaultCellStyle.BackColor = Color.Cyan
                End If
            Next
        End Sub
        <System.Diagnostics.DebuggerStepThrough()> _
        <Runtime.CompilerServices.Extension()> _
       Public Sub ConditionsBandingPrep(ByVal sender As Windows.Forms.DataGridView)
            For Row As Integer = 0 To sender.Rows.Count - 1
                If sender.Rows(Row).Cells("Column1").Value.ToString.Length = 4 Then
                    sender.Rows(Row).Tag = ConditionalFont
                End If
            Next
        End Sub
        <System.Diagnostics.DebuggerStepThrough()> _
        <Runtime.CompilerServices.Extension()> _
       Public Sub ConditionsBandingPrep(ByVal sender As Windows.Forms.DataGridView, _
                                        ByVal Rows As Integer)
            For row As Integer = sender.Rows.Count - 1 To Rows Step -1
                If sender.Rows(row).Cells("Column1").Value.ToString.Length = 4 Then
                    sender.Rows(row).Tag = ConditionalFont
                End If
            Next
        End Sub
    End Module

  3. #3

    Thread Starter
    PowerPoster make me rain's Avatar
    Join Date
    Sep 2008
    Location
    india/Hubli
    Posts
    2,208

    Re: Color grouping datagridview rows

    Kevin thanks
    The averted nuclear war
    My notes:

    PrOtect your PC. MSDN Functions .OOP LINUX forum
    .LINQ LINQ videous
    If some one helps you please rate them with out fail , forum doesn't expects any thing other than this

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width