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. Why a sub is not loaded in form load but in a button it is?

Why a sub is not loaded in form load but in a button it is?

Scheduled Pinned Locked Moved Visual Basic
databasequestion
5 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

    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 Try

    Then 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 Sub

    If 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

    L D 2 Replies Last reply
    0
    • D DeDelva

      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 Try

      Then 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 Sub

      If 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

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

      I suggest you add a line MessageBox.Show("Tiens, er zijn maar "+DataGridView1.Rows.Count+" rijen in mijn DGV ?!?") inside your checkfactuurvervallen() 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

      1 Reply Last reply
      0
      • D DeDelva

        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 Try

        Then 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 Sub

        If 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

        D Offline
        D Offline
        DaveAuld
        wrote on last edited by
        #3

        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

        L 1 Reply Last reply
        0
        • D DaveAuld

          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

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

          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

          D 1 Reply Last reply
          0
          • L Luc Pattyn

            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

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

            Probably I forgot all about the Shown event :doh: never use to exist before .Net 2, and probably I just got stuck in my ways!

            Dave Find Me On: Web|Facebook|Twitter|LinkedIn


            Folding Stats: Team CodeProject

            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