Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. How to specified datagrid's row backcolor

How to specified datagrid's row backcolor

Scheduled Pinned Locked Moved Visual Basic
tutorial
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    BigGirlBigEyes
    wrote on last edited by
    #1

    As my articles in datagrid has different status,so i want to differ them by different backcolor,that is i want a record displayed in datagrid changed its backcolor by its status. Looking forward to your reply. Thanks a lot!

    D 1 Reply Last reply
    0
    • B BigGirlBigEyes

      As my articles in datagrid has different status,so i want to differ them by different backcolor,that is i want a record displayed in datagrid changed its backcolor by its status. Looking forward to your reply. Thanks a lot!

      D Offline
      D Offline
      Dr_X
      wrote on last edited by
      #2

      You will have to do it in the ItemDataBound event. Every row that is created will fire this event before creating the actual row.

      private grid_ItemDataBound(Byval sender as system.object, byval e as DataGridItemEventArgs) handles grid.ItemDataBound
      If e.item.itemtype = ListItemType.Item or ListItemType.AlternatingItem then
      'You can do this
      dim r as TableCellCollection = e.item.Cells
      r.item(0).BackColor = Color.Coral
      'or
      i = 0
      e.item.cells(i).BackColor = Color.FireBrick
      End if
      end sub

      Oops, I thought I was in the ASP.Net section. However, this still may be helpful. Hope this helps, Michael I firmly believe that any man's finest hour, the greatest fulfillment of all that he holds dear, is that moment when he has worked his heart out in a good cause and lies exhausted on the field of battle - victorious. Vince Lombardi (1913-1970)

      B 1 Reply Last reply
      0
      • D Dr_X

        You will have to do it in the ItemDataBound event. Every row that is created will fire this event before creating the actual row.

        private grid_ItemDataBound(Byval sender as system.object, byval e as DataGridItemEventArgs) handles grid.ItemDataBound
        If e.item.itemtype = ListItemType.Item or ListItemType.AlternatingItem then
        'You can do this
        dim r as TableCellCollection = e.item.Cells
        r.item(0).BackColor = Color.Coral
        'or
        i = 0
        e.item.cells(i).BackColor = Color.FireBrick
        End if
        end sub

        Oops, I thought I was in the ASP.Net section. However, this still may be helpful. Hope this helps, Michael I firmly believe that any man's finest hour, the greatest fulfillment of all that he holds dear, is that moment when he has worked his heart out in a good cause and lies exhausted on the field of battle - victorious. Vince Lombardi (1913-1970)

        B Offline
        B Offline
        BigGirlBigEyes
        wrote on last edited by
        #3

        I have solved my problem by your hints.Perhaps I didn't express my problem very well. Anyhow,thanks a lot. Following are my code: :-O:-O Sub dgArticles_ItemDataBound(ByVal sender As Object, ByVal e As DataGridItemEventArgs) Dim item As DataGridItem For Each item In dgArticles.Items 'put your judge condition here 'assumed it return 1 and 2 Select Case CurrentStatus Case "1" item.BackColor = Color.Coral Case "2" item.BackColor = Color.Beige Case Else 'do nothing End Select Next item end sub I hope I can get your help when i am in need on program. May you happy!

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups