Why a sub is not loaded in form load but in a button it is?
-
Private Sub factuurZoeken_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
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")
'hier kleuren:
DataGridView1.AutoResizeColumns()
checkfactuurvervallen()
oleConn.Close()
Catch ex As Exception
MessageBox.Show("Fout in Database : " & ex.Message)
oleConn.Close()
End TryThen my sub factuurvervallen:
Private Sub checkfactuurvervallen()
'kleur records indien vrij of niet(haal datum vandaag op)
Try
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
Catch ex As Exception
MessageBox.Show("Fout in kleuren aangeven : " & ex.Message)
End Try
'tot hier kleuren
End SubIf i pass the sub factuurvervallen() on a button it colors the rows but in my load after loading the rows it doesn't what am i overseeing?? thx in advance
-
Private Sub factuurZoeken_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
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")
'hier kleuren:
DataGridView1.AutoResizeColumns()
checkfactuurvervallen()
oleConn.Close()
Catch ex As Exception
MessageBox.Show("Fout in Database : " & ex.Message)
oleConn.Close()
End TryThen my sub factuurvervallen:
Private Sub checkfactuurvervallen()
'kleur records indien vrij of niet(haal datum vandaag op)
Try
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
Catch ex As Exception
MessageBox.Show("Fout in kleuren aangeven : " & ex.Message)
End Try
'tot hier kleuren
End SubIf i pass the sub factuurvervallen() on a button it colors the rows but in my load after loading the rows it doesn't what am i overseeing?? thx in advance
I suggest you add a line
MessageBox.Show("Tiens, er zijn maar "+DataGridView1.Rows.Count+" rijen in mijn DGV ?!?")
inside yourcheckfactuurvervallen()
and then think about the result you are getting. BTW: Looking at some actual values is the most essential part of debugging. :)Luc Pattyn [My Articles] Nil Volentibus Arduum
-
Private Sub factuurZoeken_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
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")
'hier kleuren:
DataGridView1.AutoResizeColumns()
checkfactuurvervallen()
oleConn.Close()
Catch ex As Exception
MessageBox.Show("Fout in Database : " & ex.Message)
oleConn.Close()
End TryThen my sub factuurvervallen:
Private Sub checkfactuurvervallen()
'kleur records indien vrij of niet(haal datum vandaag op)
Try
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
Catch ex As Exception
MessageBox.Show("Fout in kleuren aangeven : " & ex.Message)
End Try
'tot hier kleuren
End SubIf i pass the sub factuurvervallen() on a button it colors the rows but in my load after loading the rows it doesn't what am i overseeing?? thx in advance
I have been caught out by this before. Certain things cannot be done within the Load event because the form has not fully loaded yet. What I have done as a work around in the past is create a one off timer which is set for 250ms (or suitable time for your needs) and in the tick event call a sub that has the stuff you want to occur at load. The timer should be long enough to allow the form to display. Works just fine.
Dave Find Me On: Web|Facebook|Twitter|LinkedIn
Folding Stats: Team CodeProject
-
I have been caught out by this before. Certain things cannot be done within the Load event because the form has not fully loaded yet. What I have done as a work around in the past is create a one off timer which is set for 250ms (or suitable time for your needs) and in the tick event call a sub that has the stuff you want to occur at load. The timer should be long enough to allow the form to display. Works just fine.
Dave Find Me On: Web|Facebook|Twitter|LinkedIn
Folding Stats: Team CodeProject
wouldn't the Shown event be good enough here? I expect all outstanding Windows messages caused inside the Load handler will have been processed by then and the DGV will have been fully populated. :)
Luc Pattyn [My Articles] Nil Volentibus Arduum
-
wouldn't the Shown event be good enough here? I expect all outstanding Windows messages caused inside the Load handler will have been processed by then and the DGV will have been fully populated. :)
Luc Pattyn [My Articles] Nil Volentibus Arduum