-
May 13th, 2022, 12:47 PM
#1
Thread Starter
New Member
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
-
May 13th, 2022, 03:36 PM
#2
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)
-
May 13th, 2022, 06:29 PM
#3
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
-
May 14th, 2022, 04:42 AM
#4
Thread Starter
New Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|