This is a migrated thread and some comments may be shown as answers.
Save Text State of Dynamically Created Buttons RagGridView
1 Answer 2 Views
This is a migrated thread and some comments may be shown as answers.
Top achievements
Rank 1
Raphael asked on 05 Feb 2016, 05:19 PM

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



1 Answer, 1 is accepted

Sort by
Telerik team
answered on 08 Feb 2016, 09:11 AM
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
Asked by
Top achievements
Rank 1
Answers by
Telerik team
Share this question