RadGrid - Using a checkbox to add rows to the selectedrows collection

2 posts, 0 answers
  1. Jon
    Jon avatar
    11 posts
    Member since:
    Sep 2012

    Posted 31 Jul 2013 Link to this post

    I've been reading through the tutorials and forums to see if this is possible or if maybe my approach is wrong. Here's what i am doing.

    I am using a pretty simple grid with an id number in the second column.  The first column is a checkbox cell.  All I want to do is to check the checkbox of say 4 or 5 of the rows and them ask the grid which rows have been selected.  Does the grid's selected rows collection maintain this for me or do I have to code this myself to store the key's seperately, which is easy enough to do.  But from looking at the various forum threads, it looks like the grid will do this if you allow mulitple row selections.  But when I set this and check the selectedrows collection, it is always empty.

    This sounds like a VERY common question and approach, but I cannot find the anwser.  What I would like to do is something like the following.  This doesn't work because the selectedrows(0) is always empty.  In fact, when I view just the selectedrows, the count is always 0.  So the grid is not keeping track of this for me.

    I do have the option turned on to select multiple rows.  I can add my own logic to track this, but I think the grid is handling it based on other threads and the sample code below. 

    Private Sub dgvLoanRestore_ValueChanged(sender As System.Object, e As System.EventArgs) Handles dgvLoanRestore.ValueChanged
                Dim selectedRows As New List(Of GridViewDataRowInfo)
                Dim item As Object = dgvLoanBackup.SelectedRows(0).DataBoundItem
                ' Recount rows selected (i.e. the number of checked checkboxes in the grid)
                lblSelectedRowCount.Text = selectedRows.Count.ToString()
            End Sub

  2. Anton
    Anton avatar
    167 posts

    Posted 02 Aug 2013 Link to this post

    Hi Jon,

    Thank you for writing.

    The CheckBox in the cells in RadGridView display just one value (true or false) and this value does not have relation with the selection of the row. So, it is normal the SelectedRows collection of RadGridView to be empty in this case. However, if you want to know which rows are selected you can use the following approach:
        If TypeOf Me.radGridView1.ActiveEditor Is RadCheckBoxEditor Then
        End If
        Dim counter As Integer
        For Each rowInfo As GridViewRowInfo In radGridView1.Rows
            If rowInfo.Cells(0).Value = True Then
                counter = counter + 1
            End If
    End Sub

    Attached is the demo project that demonstrates this approach in action.

    I hope this helps.

    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