Where and Why my row is not collored
-
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....
-
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....
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
-
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....
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
-
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
-
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
-
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
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
NextoleConn.Close()
I hope is more clear now Thx 4 the answers already greetz
-
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