Solved

VB.Net2 Change text on individual button in Datagridview

Posted on 2013-05-16
3
1,660 Views
Last Modified: 2013-05-17
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
0
Comment
Question by:PNRT
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 39171550
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
0
 
LVL 2

Author Comment

by:PNRT
ID: 39172538
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.
0
 
LVL 83

Accepted Solution

by:
CodeCruiser earned 500 total points
ID: 39174304
Ah sorry I missed the datagridview part. You will need to handle the CellClick event of the grid and if clicked cell is button cell then set cell's value to On and Off based on existing value

Something like this

Private Sub dataGridView1_CellClick(ByVal sender As Object, ByVal e As DataGridViewCellEventArgs) Handles dataGridView1.CellClick

        ' Ignore clicks that are not on button cells.  
        If e.ColumnIndex = YourButtonColumnIndex Then
            If datagridView1.Item(e.ColumnIndex, e.RowIndex).Value.Tostring = "On" Then
               datagridView1.Item(e.ColumnIndex, e.RowIndex).Value = "Off"
            Else
               datagridView1.Item(e.ColumnIndex, e.RowIndex).Value = "On"
            End If
        End If

        ' Retrieve the task ID.
        Dim taskID As Int32 = CInt(dataGridView1(0, e.RowIndex).Value)
    End Sub
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: Kraeven
Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …

626 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question