none
How come my table goes away when I start my Code? RRS feed

  • Question

  • HI,

    So, I added a table to my program, but when I run it, the table goes away. I Wanted to know if there was a way to like "Lock" the table so it will appear when you run the program.

    Tuesday, October 2, 2018 8:03 PM

Answers

  • Going with your last question the table (DataGridView) stays where it should.

    https://social.msdn.microsoft.com/Forums/vstudio/en-US/0283c85f-dc1d-4933-9d7d-f61e1bc9e592/table-in-vb?forum=vbgeneral#24735c88-2a01-4040-8d24-a87597d8a478

    Public Class Form1
        Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
            DataGridView1.RowHeadersVisible = False
    
            DataGridView1.ColumnHeadersVisible = False
            DataGridView1.Rows.Add("", "", "", "", "")
    
            DataGridView1.Rows.Add("", "", "", "", "")
    
            DataGridView1.Rows.Add("", "", "", "", "")
    
            DataGridView1.Rows.Add("", "", "", "", "")
    
            DataGridView1.Rows.Add("", "", "", "", "")
            DataGridView1.AllowUserToResizeRows = False
    
            DataGridView1.AllowUserToResizeColumns = False
        End Sub
    End Class

    Option 2

    Public Class Form1
        Private DataGridView1 As New DataGridView With {.Dock = DockStyle.Fill}
        Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
    
            DataGridView1.Columns.Add(New DataGridViewTextBoxColumn With {.Name = "C1"})
            DataGridView1.Columns.Add(New DataGridViewTextBoxColumn With {.Name = "C2"})
            DataGridView1.Columns.Add(New DataGridViewTextBoxColumn With {.Name = "C3"})
            DataGridView1.Columns.Add(New DataGridViewTextBoxColumn With {.Name = "C4"})
            DataGridView1.Columns.Add(New DataGridViewTextBoxColumn With {.Name = "C5"})
    
            DataGridView1.RowHeadersVisible = False
    
            DataGridView1.ColumnHeadersVisible = False
            DataGridView1.Rows.Add("", "", "", "", "")
    
            DataGridView1.Rows.Add("", "", "", "", "")
    
            DataGridView1.Rows.Add("", "", "", "", "")
    
            DataGridView1.Rows.Add("", "", "", "", "")
    
            DataGridView1.Rows.Add("", "", "", "", "")
            DataGridView1.AllowUserToResizeRows = False
    
            DataGridView1.AllowUserToResizeColumns = False
    
            Controls.Add(DataGridView1)
        End Sub
    End Class
    


    Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.
    VB Forums - moderator
    profile for Karen Payne on Stack Exchange, a network of free, community-driven Q&A sites


    Tuesday, October 2, 2018 8:22 PM
    Moderator

All replies

  • Hi

    You will need to be much more detailrd.

    What do you meanby a Table? A DataGridView perhaps, or, a DataTable, or, a FlowLayOutPanel, or, a TableLayOutPanel?

    *

    The quality of an answer is completely dependant on the quality of the question.


    Regards Les, Livingston, Scotland

    Tuesday, October 2, 2018 8:21 PM
  • Going with your last question the table (DataGridView) stays where it should.

    https://social.msdn.microsoft.com/Forums/vstudio/en-US/0283c85f-dc1d-4933-9d7d-f61e1bc9e592/table-in-vb?forum=vbgeneral#24735c88-2a01-4040-8d24-a87597d8a478

    Public Class Form1
        Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
            DataGridView1.RowHeadersVisible = False
    
            DataGridView1.ColumnHeadersVisible = False
            DataGridView1.Rows.Add("", "", "", "", "")
    
            DataGridView1.Rows.Add("", "", "", "", "")
    
            DataGridView1.Rows.Add("", "", "", "", "")
    
            DataGridView1.Rows.Add("", "", "", "", "")
    
            DataGridView1.Rows.Add("", "", "", "", "")
            DataGridView1.AllowUserToResizeRows = False
    
            DataGridView1.AllowUserToResizeColumns = False
        End Sub
    End Class

    Option 2

    Public Class Form1
        Private DataGridView1 As New DataGridView With {.Dock = DockStyle.Fill}
        Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
    
            DataGridView1.Columns.Add(New DataGridViewTextBoxColumn With {.Name = "C1"})
            DataGridView1.Columns.Add(New DataGridViewTextBoxColumn With {.Name = "C2"})
            DataGridView1.Columns.Add(New DataGridViewTextBoxColumn With {.Name = "C3"})
            DataGridView1.Columns.Add(New DataGridViewTextBoxColumn With {.Name = "C4"})
            DataGridView1.Columns.Add(New DataGridViewTextBoxColumn With {.Name = "C5"})
    
            DataGridView1.RowHeadersVisible = False
    
            DataGridView1.ColumnHeadersVisible = False
            DataGridView1.Rows.Add("", "", "", "", "")
    
            DataGridView1.Rows.Add("", "", "", "", "")
    
            DataGridView1.Rows.Add("", "", "", "", "")
    
            DataGridView1.Rows.Add("", "", "", "", "")
    
            DataGridView1.Rows.Add("", "", "", "", "")
            DataGridView1.AllowUserToResizeRows = False
    
            DataGridView1.AllowUserToResizeColumns = False
    
            Controls.Add(DataGridView1)
        End Sub
    End Class
    


    Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.
    VB Forums - moderator
    profile for Karen Payne on Stack Exchange, a network of free, community-driven Q&A sites


    Tuesday, October 2, 2018 8:22 PM
    Moderator
  • Sorry, I am talking about a TableLayOutPanel
    Tuesday, October 2, 2018 8:42 PM
  • much thanks
    Tuesday, October 2, 2018 8:47 PM
  • Hi

    OK, try this.

    If you already have the Form Load eveny handler, then add this line in it.

      TableLayoutPanel1.BackColor = Color.Pink
    

    or, if you don't yet have that handler then add this in your code:

      Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        TableLayoutPanel1.BackColor = Color.Pink
      End Sub

    (certain assumtions made - eg Form1 is your Form name etc)

    If my guess is correct, then the control didn't disappear, just didn't have anything there to see!


    Regards Les, Livingston, Scotland


    • Edited by leshay Tuesday, October 2, 2018 8:55 PM
    Tuesday, October 2, 2018 8:54 PM