This is a migrated thread and some comments may be shown as answers.

CheckBoxColumn FindControl

3 Answers 138 Views
GridView
This is a migrated thread and some comments may be shown as answers.
jose luis
Top achievements
Rank 1
jose luis asked on 20 Jan 2011, 05:28 AM
Hello telerik team! ..

hope u are fine ..

My question is...

I have a gridview with a CeckBoxColumn  .. and i want to do something like this... but i don't know how (i'm in VB by the way)

For each x as .... = 0 to grid.rows.count -1 step 1
    dim box as checkbox
    box = REM code here to reference the checkbox in the row 'x'
    if box.checked = true then
        REM some code
    else
        REM some code
    end if
next

i want the exact code , i try myself but i don't get it  :(

thanks al the answers!!

3 Answers, 1 is accepted

Sort by
0
Emanuel Varga
Top achievements
Rank 1
answered on 20 Jan 2011, 08:42 AM
Hello Jose,

You can use something like this to parse all the rows, and get the values from the cells from the checkbox column:
For Each row As var In radGridView1.Rows
    Dim value As Boolean = False
    Dim cellValue = row.Cells("CheckBoxColumn").Value
    If cellValue IsNot Nothing Then
        Boolean.TryParse(cellValue.ToString(), value)
    End If
 
 
    If value Then
 
    Else
    End If
Next

Hope this helps, if you have any other questions or comments, please let me know,

Best Regards,
Emanuel Varga
Telerik WinForms MVP
0
jose luis
Top achievements
Rank 1
answered on 20 Jan 2011, 09:35 PM
Hi emanuel , thanks for the answer

i almost have it...................

i finally found the checkbox for each row in the grid .. but this is what happens :

***  If i check more than one checkBox .. the UPDATE command only works for the FIRST row  i have checked the checkbox...
almost done i think this will be my last question.. lots of thankss...

here is my code..


Private

 

Sub btnCheck_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCheck.Click

 

 

 

For i As Integer = 0 To Me.dgUno.Rows.Count - 1 Step 1

 

 

 

Dim value As Boolean = False

 

 

 

Dim cellValue = Me.dgUno.Rows(i).Cells("Chk").Value

 

 

 

If cellValue IsNot Nothing Then

 

 

 

Boolean.TryParse(cellValue.ToString(), value)

 

 

 

End If

 

 

 

Dim clave As Integer

 

 

clave =

Me.dgUno.Rows(i).Cells(1).Value

 

 

 

 

If value = True Then

 

 

aumento(clave)

 

End If

 

 

 

Next

 

 

 

End Sub

 

 

 

Sub aumento(ByVal id As Integer)

 

 

 

Dim con As New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=Tienda.accdb;Persist Security Info=False")

 

 

 

Dim comando As New OleDbCommand

 

 

 

Try

 

 

con.Open()

comando.Connection = con

comando.CommandType = CommandType.Text

comando.CommandText =

"UPDATE PRODUCTO SET precio = precio + 200 WHERE idproducto = @CLAVE"

 

 

comando.Parameters.Add(

New OleDbParameter("@CLAVE", id))

 

comando.ExecuteNonQuery()

 

 

Catch ex As Exception

 

MsgBox(ex.Message)

 

 

Finally

 

 

con.Close()

 

End Try

 

 

grid()

 

End Sub

 

 

0
Richard Slade
Top achievements
Rank 2
answered on 20 Jan 2011, 10:02 PM
Hello Jose Luis,

This is all you should need to loop over the RadGridView Rows and call your method in the place commented in the code. Note that I have also used column name, not ordinal position to reference the cell as this can change if you allow columns to be re-ordered.

Private Sub RadButton1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadButton1.Click
    For Each row As GridViewRowInfo In Me.RadGridView1.Rows
        Dim cellValue = row.Cells("Chk").Value '// use column name. Not ordinal position. This can change with column re-ordering
        Dim result As Boolean
        If cellValue IsNot Nothing Then
            Boolean.TryParse(cellValue.ToString(), result)
        End If
        If result Then
            '// Call your method here
            MessageBox.Show("Row Index: " & row.Index.ToString() & " is  " & result.ToString())
        End If
    Next
End Sub

Hope that helps
Richard
Tags
GridView
Asked by
jose luis
Top achievements
Rank 1
Answers by
Emanuel Varga
Top achievements
Rank 1
jose luis
Top achievements
Rank 1
Richard Slade
Top achievements
Rank 2
Share this question
or