Removing Row and setting previous row as active.

3 posts, 0 answers
  1. James
    James avatar
    2 posts
    Member since:
    Oct 2013

    Posted 17 Oct 2013 Link to this post

    What is the proper way to remove a row and set the previous row as active(if # of rows > 0) on a sorted and/or filtered and/or grouped radGridView?
    I populate my radGridView manually with a stored procedure.
    The first column in the rGV is a button column when the user presses the button the row should be removed and the previous row set as active/current.
    I had this working perfectly when using the DataGridView included with VS2012 but now I'm getting an IndexOutOfRangeException thrown.


    Private Sub DataGridView4_CellContentClick(ByVal sender As System.Object, ByVal e As Telerik.WinControls.UI.GridViewCellEventArgs) Handles DataGridView4.CellClick
        If e.ColumnIndex = 0 Then
            intDataGridSelectedIndexRenewalC = DataGridView4.CurrentRow.Index
            If sps_EIPHasBeenBilled(DataGridView4.CurrentRow.Cells("Policy_no").Value.ToString) Then
                MsgBox("Unable to Mark This Policy as Complete! " & DataGridView4.CurrentRow.Cells("Policy_no").Value.ToString & " Has Not been Billed Yet.", vbOKOnly)
            End If
        End If
    End Sub
    Private Sub RenewalsCommercialMarkComplete()
        Dim UpdateStatus As Boolean
        Dim SQLQuery As String = "exec " & strDefaultDatabase & ".dbo.spu_EIPRenewalMarkCompleteByRenewalID '" & DataGridView4.CurrentRow.Cells("RenewalsID").Value & "', '" & strLoggedInUserFullName & "'"
        If MsgBox("Do you wish to mark this record: " & DataGridView4.CurrentRow.Cells("Customer").Value.ToString & ": " & DataGridView4.CurrentRow.Cells("Policy_no").Value.ToString & " as complete?", vbYesNo + vbQuestion, "Renewal Mark Complete") = vbYes Then
            UpdateStatus = WriteSQL_Data(SQLQuery)
            If UpdateStatus Then
                MsgBox("Record: " & DataGridView4.CurrentRow.Cells("Policy_no").Value.ToString & " Marked As Complete!", MsgBoxStyle.OkOnly)
                If (intDataGridSelectedIndexRenewalC - 1) > 0 Then
                    DataGridView4.ChildRows(intDataGridSelectedIndexRenewalC - 1).IsSelected = True
                    DataGridView4.ChildRows(intDataGridSelectedIndexRenewalC - 1).IsCurrent = True
                End If
                MsgBox("Unable to Connect to Database Please see your System Administrator with Error: Summary - ButtonOk_Click: ", vbOK)
            End If
            MsgBox("The Operation was Cancelled", vbOKOnly)
        End If
    End Sub
  2. Brent
    Brent avatar
    6 posts
    Member since:
    Jun 2012

    Posted 18 Oct 2013 Link to this post

    It seems the errors are only occurring when the rGV has grouping applied.
    This means I need to check for grouping before attempting to remove the row and set the previous row as active.
    The code I posted works fine for a filtered rGV.
    I'm looking for an example of removing a row from a grouped rGV, I found the following code but the TryCast is not working(always returns nothing).
    Private Sub DeleteGroupRow()
     Dim groupRow As GridViewGroupRowInfo = TryCast(radGridView4.CurrentRow, GridViewGroupRowInfo)
     If groupRow IsNot Nothing Then 
     End If
    End Sub
  3. Dess | Tech Support Engineer, Sr.
    Dess | Tech Support Engineer, Sr.  avatar
    3945 posts

    Posted 21 Oct 2013 Link to this post


    Thank you for contacting Telerik Support.

    Please have a look at the following code snippet, demonstrating current row removing when clicking on the GridCommandCellElement and selecting the previous row. The sample code should work properly for grouped grid, as well as for filtered grid:
    Public Class Form1
        Sub New()
            Me.RadGridView1.EnableFiltering = True
            Dim idColumn As New GridViewTextBoxColumn("ID column")
            Dim commandColumn As New GridViewCommandColumn("Command column")
            Dim textBoxColumn As New GridViewTextBoxColumn("Title column")
            Dim checkBoxColumn As New GridViewCheckBoxColumn("Is checked")
            Dim isChecked As Boolean = False
            For i As Integer = 0 To 9
                If i Mod 2 = 0 Then
                    isChecked = True
                    isChecked = False
                End If
                Me.RadGridView1.Rows.Add(i + 1, "click", "sample title", isChecked)
            AddHandler Me.RadGridView1.CommandCellClick, AddressOf radGridView1_CommandCellClick
        End Sub
        Private Sub radGridView1_CommandCellClick(sender As Object, e As EventArgs)
            Dim commandCell As GridCommandCellElement = TryCast(sender, GridCommandCellElement)
            If commandCell IsNot Nothing AndAlso commandCell.RowIndex >= 0 Then
            End If
        End Sub
    End Class

    I hope this information helps. Should you have further questions, I would be glad to help.

    Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
    Sign up for Free application insights >>
Back to Top