Link to home
Start Free TrialLog in
Avatar of PNRT
PNRT

asked on

VB.Net2 Change text on individual button in Datagridview

Hi Experts.  I have a datagridview with a column of buttons that all start off with the text "Off".  

I want to be able to change the text to "On" when the button is pressed and back to "Off when pressed again.    So some will say "Off"  and Some "On".   Please could someone help with an example of how this could be done?  

I will also need to get the condition of the button later, whether its text is "Off" or "On".   Help there would also be appreciated.    Many Thanks for the help
Avatar of Nasir Razzaq
Nasir Razzaq
Flag of United Kingdom of Great Britain and Northern Ireland image

Every control has a Tag property. You can store True or False in this property to indicate current state

Button1_Click:
Button1.Tag = Not Button1.Tag

If Button1.Tag Then
    Button1.Text = "On"
Else
    Button1.Text = "Off"
End If
Avatar of PNRT
PNRT

ASKER

Thanks for the reply Codecruiser, but how do I get the button click of the button in the particular row of the datagridview.     I can see how to do it with a normal button but I need to do it with the individual buttons in the datagridview column.  Thanks again.
ASKER CERTIFIED SOLUTION
Avatar of Nasir Razzaq
Nasir Razzaq
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial