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

[Solved] How to Reference Checkbox

2 Answers 205 Views
GridView
This is a migrated thread and some comments may be shown as answers.
JustinWong
Top achievements
Rank 1
JustinWong asked on 08 Apr 2010, 07:15 PM
Hi:

Let's say I have a RadGridView called RGV. There is a CheckboxColumn (uniquename = "col1").  How can I reference the check box in row 6 of that column and change the check box value under two secnario:

1. I click a button somewhere in the form, and I need to change the checkbox on row 6 to true.
2. During the RGV.CellFormatting event, I need to set the checkbox of each row to true or false based on some predetermined factor.

If I could see some VB code example on how to acheive that, I'd be grateful.

Thanks,

Justin

2 Answers, 1 is accepted

Sort by
0
Mathieu Yargeau
Top achievements
Rank 1
answered on 09 Apr 2010, 01:16 AM
Hello,

I don't program in VB, but in C#. However, it should not be that different.

For your first question, you can do this:

radGridView1.Rows[6].Cells["col1"].Value = true

For your second question:

void radGridView1_CellFormatting(object sender, CellFormattingEventArgs e)  
{  
    if (radGridView1.Columns[e.CellElement.ColumnIndex].UniqueName == "col1")  
    {  
        GridViewCellInfo cell = e.CellElement.RowInfo.Cells[e.CellElement.ColumnIndex];  
 
        if (Condition == true)  
        {  
            cell.Value = true;  
        }  
        else 
        {  
            cell.Value = false;  
        }  
    }  

 

Here I check if the cell being formatted is in the CheckBoxColumn, recuperates the grid's cell and set the right value.

0
Jack
Telerik team
answered on 12 Apr 2010, 02:39 PM
Hello Justin, Mathieu Yargeau,

Thank you for your help. A better option is to use the UniqueName property instead of the ColumnIndex, which is calculated dynamically every time. Here is the code in VB:

Private Sub RadGridView1_CellFormatting(ByVal sender As Object, ByVal e As Telerik.WinControls.UI.CellFormattingEventArgs) Handles RadGridView1.CellFormatting
    Dim column As GridViewDataColumn = TryCast(e.CellElement.ColumnInfo, GridViewDataColumn)
    Dim cell As GridDataCellElement = TryCast(e.CellElement, GridDataCellElement)
    If column IsNot Nothing And column.UniqueName = "col1" Then
        cell.Value = Condition
    End If
End Sub

I hope this helps.

 

Kind regards,
Jack
the Telerik team

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 Public Issue Tracking system and vote to affect the priority of the items.
Tags
GridView
Asked by
JustinWong
Top achievements
Rank 1
Answers by
Mathieu Yargeau
Top achievements
Rank 1
Jack
Telerik team
Share this question
or