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. Where and Why my row is not collored

Where and Why my row is not collored

Scheduled Pinned Locked Moved Visual Basic
7 Posts 3 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.
  • D Offline
    D Offline
    DeDelva
    wrote on last edited by
    #1

    Try m_SelectedStyle = New DataGridViewCellStyle() m_SelectedStyle.BackColor = Color.LightBlue m_SelectedStyle.BackColor = SystemColors.Highlight DataGridView1.ReadOnly = True Dim SQLString As String = "SELECT id, bedrijfsnaam, startdatum, vervaldatum, omschrijving, netto, bruto, opmerkingen FROM Facturen" Dim DataSet As New DataSet() Dim OleDbDataAdapter As System.Data.OleDb.OleDbDataAdapter = New System.Data.OleDb.OleDbDataAdapter(SQLString, oleConn) oleConn.Open() OleDbDataAdapter.Fill(DataSet, "Facturen") DataGridView1.DataSource = DataSet.Tables("Facturen") 'here the colors starts DataGridView1.Rows(1).DefaultCellStyle.BackColor = Color.Blue Dim vandaag As String = Today Dim i As Integer = 0 For Each row As DataGridViewRow In DataGridView1.Rows If DataGridView1.Item(2, i).Value() = vandaag Then DataGridView1.Rows(i).DefaultCellStyle.BackColor = Color.IndianRed ElseIf DataGridView1.Item(2, i).Value() > vandaag Then DataGridView1.Rows(i).DefaultCellStyle.BackColor = Color.LightGreen End If i = i + 1 Next DataGridView1.AutoResizeColumns() oleConn.Close() Catch ex As Exception blabla End Try Even if i try to just color without conditions it doesnt work something like: DataGridView1.Rows(2).DefaultCellStyle.BackColor = Color.LightGreen But whyyyyy....

    L S 2 Replies Last reply
    0
    • D DeDelva

      Try m_SelectedStyle = New DataGridViewCellStyle() m_SelectedStyle.BackColor = Color.LightBlue m_SelectedStyle.BackColor = SystemColors.Highlight DataGridView1.ReadOnly = True Dim SQLString As String = "SELECT id, bedrijfsnaam, startdatum, vervaldatum, omschrijving, netto, bruto, opmerkingen FROM Facturen" Dim DataSet As New DataSet() Dim OleDbDataAdapter As System.Data.OleDb.OleDbDataAdapter = New System.Data.OleDb.OleDbDataAdapter(SQLString, oleConn) oleConn.Open() OleDbDataAdapter.Fill(DataSet, "Facturen") DataGridView1.DataSource = DataSet.Tables("Facturen") 'here the colors starts DataGridView1.Rows(1).DefaultCellStyle.BackColor = Color.Blue Dim vandaag As String = Today Dim i As Integer = 0 For Each row As DataGridViewRow In DataGridView1.Rows If DataGridView1.Item(2, i).Value() = vandaag Then DataGridView1.Rows(i).DefaultCellStyle.BackColor = Color.IndianRed ElseIf DataGridView1.Item(2, i).Value() > vandaag Then DataGridView1.Rows(i).DefaultCellStyle.BackColor = Color.LightGreen End If i = i + 1 Next DataGridView1.AutoResizeColumns() oleConn.Close() Catch ex As Exception blabla End Try Even if i try to just color without conditions it doesnt work something like: DataGridView1.Rows(2).DefaultCellStyle.BackColor = Color.LightGreen But whyyyyy....

      L Offline
      L Offline
      Luc Pattyn
      wrote on last edited by
      #2

      Hi, 1. that is unreadable; use PRE tags to get a non-prop font and proper indentation. 2. don't swallow exceptions, they provide useful information. 3. in my experience, DGV backcolor only works on non-empty cells. My "CP Vanity" article uses it a lot (it is C#, doesn't really matter). :)

      Luc Pattyn [My Articles] Nil Volentibus Arduum

      S D 2 Replies Last reply
      0
      • D DeDelva

        Try m_SelectedStyle = New DataGridViewCellStyle() m_SelectedStyle.BackColor = Color.LightBlue m_SelectedStyle.BackColor = SystemColors.Highlight DataGridView1.ReadOnly = True Dim SQLString As String = "SELECT id, bedrijfsnaam, startdatum, vervaldatum, omschrijving, netto, bruto, opmerkingen FROM Facturen" Dim DataSet As New DataSet() Dim OleDbDataAdapter As System.Data.OleDb.OleDbDataAdapter = New System.Data.OleDb.OleDbDataAdapter(SQLString, oleConn) oleConn.Open() OleDbDataAdapter.Fill(DataSet, "Facturen") DataGridView1.DataSource = DataSet.Tables("Facturen") 'here the colors starts DataGridView1.Rows(1).DefaultCellStyle.BackColor = Color.Blue Dim vandaag As String = Today Dim i As Integer = 0 For Each row As DataGridViewRow In DataGridView1.Rows If DataGridView1.Item(2, i).Value() = vandaag Then DataGridView1.Rows(i).DefaultCellStyle.BackColor = Color.IndianRed ElseIf DataGridView1.Item(2, i).Value() > vandaag Then DataGridView1.Rows(i).DefaultCellStyle.BackColor = Color.LightGreen End If i = i + 1 Next DataGridView1.AutoResizeColumns() oleConn.Close() Catch ex As Exception blabla End Try Even if i try to just color without conditions it doesnt work something like: DataGridView1.Rows(2).DefaultCellStyle.BackColor = Color.LightGreen But whyyyyy....

        S Offline
        S Offline
        Scubapro
        wrote on last edited by
        #3

        That's because you got a bounded datagridview. If you want colors, you'll need to put it in a CellFormatting Sub, like so:

        Public Sub DataGridView1_CellFormatting(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellFormattingEventArgs) Handles DataGridView1.CellFormatting

        '...do your coloring thing

        End Sub

        D 1 Reply Last reply
        0
        • L Luc Pattyn

          Hi, 1. that is unreadable; use PRE tags to get a non-prop font and proper indentation. 2. don't swallow exceptions, they provide useful information. 3. in my experience, DGV backcolor only works on non-empty cells. My "CP Vanity" article uses it a lot (it is C#, doesn't really matter). :)

          Luc Pattyn [My Articles] Nil Volentibus Arduum

          S Offline
          S Offline
          Scubapro
          wrote on last edited by
          #4

          1. True. 2. True. 3. Not True.

          1 Reply Last reply
          0
          • S Scubapro

            That's because you got a bounded datagridview. If you want colors, you'll need to put it in a CellFormatting Sub, like so:

            Public Sub DataGridView1_CellFormatting(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellFormattingEventArgs) Handles DataGridView1.CellFormatting

            '...do your coloring thing

            End Sub

            D Offline
            D Offline
            DeDelva
            wrote on last edited by
            #5

            The celformatting is updating all the time... I think it's not a good practice 4 memory use etc... If i place a messagebox in the sub's it's popping up all the time... Anyway Thx greetz

            S 1 Reply Last reply
            0
            • L Luc Pattyn

              Hi, 1. that is unreadable; use PRE tags to get a non-prop font and proper indentation. 2. don't swallow exceptions, they provide useful information. 3. in my experience, DGV backcolor only works on non-empty cells. My "CP Vanity" article uses it a lot (it is C#, doesn't really matter). :)

              Luc Pattyn [My Articles] Nil Volentibus Arduum

              D Offline
              D Offline
              DeDelva
              wrote on last edited by
              #6

              The last one is indeed not true... For your first 2 points thx 4 the advice... So my code between pre thags(sorry 4 that)

              m_SelectedStyle = New DataGridViewCellStyle()
              m_SelectedStyle.BackColor = Color.LightBlue
              m_SelectedStyle.BackColor = SystemColors.Highlight
              DataGridView1.ReadOnly = True
              Dim SQLString As String = "SELECT id, bedrijfsnaam, startdatum, vervaldatum, omschrijving, netto, bruto, opmerkingen FROM Facturen"
              Dim DataSet As New DataSet()
              Dim OleDbDataAdapter As System.Data.OleDb.OleDbDataAdapter = New System.Data.OleDb.OleDbDataAdapter(SQLString, oleConn)
              oleConn.Open()
              OleDbDataAdapter.Fill(DataSet, "Facturen")
              DataGridView1.DataSource = DataSet.Tables("Facturen")
              'here i do the code to check if a field is smaller then a certain date
              Dim vandaag As String = Today
              Dim i As Integer = 0
              For Each row As DataGridViewRow In DataGridView1.Rows
              If DataGridView1.Item(2, i).Value() > vandaag Then
              DataGridView1.Rows(i).DefaultCellStyle.BackColor = Color.IndianRed
              ElseIf DataGridView1.Item(2, i).Value() < vandaag Then
              DataGridView1.Rows(i).DefaultCellStyle.BackColor = Color.LightGreen
              End If
              i = i + 1
              Next

                      oleConn.Close()
              

              I hope is more clear now Thx 4 the answers already greetz

              1 Reply Last reply
              0
              • D DeDelva

                The celformatting is updating all the time... I think it's not a good practice 4 memory use etc... If i place a messagebox in the sub's it's popping up all the time... Anyway Thx greetz

                S Offline
                S Offline
                Scubapro
                wrote on last edited by
                #7

                Ofcourse it is. It's like a Paint routine on a Form, Panel, etc. Therefore it is not a good idea to put a messagebox in there, just do your coloring.

                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