Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9071631
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T17:57:37+00:00 2026-06-16T17:57:37+00:00

Hi I have this TablelayoutPanel setup currently in my program to create a grid

  • 0

Hi I have this TablelayoutPanel setup currently in my program to create a grid of buttons that will later correspond to a specific column and row:

'****INITIALISES TABLE LAYOUT INTO FORM******
    Dim ColCount, RowCount As Integer

    'Later change so that values are automatically calculated
    ColCount = 5
    RowCount = 5

    '*********Copy and pasted from site as example, CHANGE LATER*******
    Haztable = New TableLayoutPanel
    Haztable.AutoScroll = True
    Haztable.Dock = DockStyle.Fill
    Haztable.ColumnCount = ColCount
    Haztable.RowCount = RowCount
    For rowNo As Integer = 0 To Haztable.RowCount - 1
        For columnNo As Integer = 0 To Haztable.ColumnCount - 1
            'Dim ctrl As Control = New Button
            'ctrl.Text = String.Format("{0} {1},{2}", ctrl.GetType().Name, columnNo, rowNo)
            'ctrl.Size = New Size(20, 20)
            'Haztable.Controls.Add(ctrl, columnNo, rowNo)
            Dim buttonname As String
            buttonname = "B" & columnNo & rowNo
            Dim button As Control = New Button
            button.Size = New Size(70, 20)
            button.Name = buttonname
            button.Text = buttonname
            Haztable.Controls.Add(button, columnNo, rowNo)
            AddHandler button.Click, AddressOf buttonname_Click
        Next
    Next
    Me.Controls.Add(Haztable)
    Call buttonfind()

And this all works, creating a grid of buttons, much like the layout of an excel spreadsheet.

The buttons are named according to their XY position (e.g. the button in (1,1) would be called “B11”) but the problem is I can’t seem to work out how I can address these buttons i.e

*If B(X.Y) is clicked then save boolean value that button at X,Y is pressed.

It would be great to have one algorithm to scan and check if any buttons have been pressed instead of using “Select Case” for each button.
I would just create the buttons in the designer but for my full code i’m going to need 1000+ buttons and that seems an inefficient way to do so.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T17:57:39+00:00Added an answer on June 16, 2026 at 5:57 pm

    Your buttonname_Click should have a Sender object which is the Button that you Clicked just cast it to a Button and check the name then.

    Private Sub buttonname_Click(sender As System.Object, e As System.EventArgs) 
        Dim btn As Button = CType(sender, Button)
    
        Select Case btn.Name
            Case "B11"
                'Do something
            Case "B12"
                'Do Something esle
    
                '...........
        End Select
    
    End Sub
    

    Based on your last statement see if this works you may need to build an Array or a List if you need to reference the Text elsewhere in your Program

    Private Sub buttonname_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
        Dim btn As Button = CType(sender, Button)
    
        If btn.Text = "H" Then
            btn.Text = "M"
        ElseIf btn.Text = "M" Then
            btn.Text = "L"
        ElseIf btn.Text = "L" Then
            btn.Text = ""
        Else
            btn.Text = "H"
        End If
    
    
    End Sub
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a TableLayoutPanel that contains rows of labels. This control lives on form
I have a user control that contains a 2-column TableLayoutPanel and accepts commands to
This is really simple. I have a TableLayoutPanel that is populated with controls (just
Is it possible to have a System.Windows.Forms.TableLayoutPanel fill a column before moving to the
Stack-O, I have a TableLayoutPanel with 50 rows and 6 columns. That's all well
I have a dialog with column down the right side filled with buttons. The
I have a TableLayoutPanel control that is initially empty - 0 rows and 0
I am having a WinForms control, inside that I have a TableLayoutPanel which holds
Have this strange problems on some pages that rendering of umlauts (åäö) gets wrong
Have this objects and table types: CREATE TYPE Person_typ AS OBJECT ( name CHAR(20),

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.