Save Text State of Dynamically Created Buttons RagGridView

2 posts, 0 answers
  1. Raphael
    Raphael avatar
    1 posts
    Member since:
    Dec 2011

    Posted 05 Feb 2016 Link to this post

    I have a RadGridView with a filed called Start with  dynamically created buttons. When i click on it my code changed the text of the row that was clicked to Stop if it was Start Previously. MY issue is when i click another row the previously changed text is lost and the new row shows stop. I want to save the text of all the dynamically crated buttons when one is clicked.

     Dim StartStop As New GridViewCommandColumn()
            StartStop.Name = "StartStop"
            StartStop.HeaderText = "Start"
            StartStop.UseDefaultText = True
            StartStop.DefaultText = "Start"
            StartStop.Width = 40
            StartStop.MinWidth = 40

             AddHandler RadGridView1.CommandCellClick, AddressOf radGridView1_CommandCellClick

      Sub radGridView1_CommandCellClick(ByVal sender As Object, ByVal e As EventArgs)
          Dim ID As String = TryCast(sender, GridCommandCellElement).RowIndex

          Dim StartStop As String = TryCast(sender, GridCommandCellElement).CommandButton.Text

    If StartStop = "Start" Then

                   TryCast(sender, GridCommandCellElement).CommandButton.Text = "Stop"


                   TryCast(sender, GridCommandCellElement).CommandButton.Text = "Start"

    end if

      End Sub



  2. Dimitar
    Dimitar avatar
    1932 posts

    Posted 08 Feb 2016 Link to this post

    Hello Raphael,

    Thank you for writing.

    First you need to set the Value of all cells in the command column (the default text should be used when all cells have equal text only):
    Protected Overrides Sub OnLoad(ByVal e As EventArgs)
        For Each item In radGridView1.Rows
            item.Cells("StartStop").Value = "Start"
        Next item
    End Sub

    Then you can set the cell value in the CommandCellClick event handler:
    Private Sub radGridView1_CommandCellClick(ByVal sender As Object, ByVal e As GridViewCellEventArgs)
        Dim StartStop As String = e.Value.ToString()
        If StartStop = "Start" Then
            e.Row.Cells(e.Column.Name).Value = "Stop"
            e.Row.Cells(e.Column.Name).Value = "Start"
        End If
    End Sub

    Please let me know if there is something else I can help you with. 
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Back to Top