Results 1 to 4 of 4

Thread: parse value from datagrid to button name

  1. #1

    Thread Starter
    New Member
    Join Date
    Feb 2021
    Posts
    7

    parse value from datagrid to button name

    Im building a form that has many buttons, all buttons do the same thing, add 1 everytime they are clicked. Every pressed button is sent to a datagridview along with the time they are pressed.
    Datagrid values look like this:

    a_1_serv (button name), 18:05:00(time).

    Sometimes i want to delete last row. Everything works fine so far.

    When i delete last row, i want to change the text of the button(a_1_serv). I can parse the dgv value (a_1_serv) to a variable but i cant bind it to the apropriate button name so i can control it.
    is there a way to do it?

    Thanks

  2. #2
    PowerPoster
    Join Date
    Sep 2005
    Location
    Modesto, Ca.
    Posts
    5,206

    Re: parse value from datagrid to button name

    No sure I understand what your asking. But if you need to access a button on a form by name then you can use the forms "controls" method.

    Code:
            Dim var = "Button1"
            MessageBox.Show(Me.Controls(var).Text)

  3. #3
    Karen Payne MVP kareninstructor's Avatar
    Join Date
    Jun 2008
    Location
    Oregon
    Posts
    6,686

    Re: parse value from datagrid to button name

    Consider each time a new button is created add it to a private List(Of Button), then to remove the last button, get it by index, pass it to Controls.Remove then remove it from the list via Remove. Prior to removing a button assert there are buttons in the list.

    Written in note pad

    Code:
    Private Sub DeleteLast_Click(ByVal sender As Object, ByVal e As EventArgs)
        If ButtonsList.Count <= 0 Then
            Return
        End If
        Dim button = ButtonsList(ButtonsList.Count -1)
        Controls.Remove(button)
        ButtonsList.Remove(button)
    End Sub

  4. #4

    Thread Starter
    New Member
    Join Date
    Feb 2021
    Posts
    7

    Re: parse value from datagrid to button name

    Thank you for your posts, i found the solution to my problem

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width