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

Selecting value from Grid

1 Answer 71 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Juan
Top achievements
Rank 1
Juan asked on 15 Aug 2012, 09:04 PM
Hello guys;
I was trying to select the value from a specifc cell in a radGrid who has been previouisly check with a check column. I tried using the ValueChanged event but still it doesn't work. I looked all over the forum but still couldn't get the value. My code in general looks like this:
private void grdClientes_ValueChanged(object sender, EventArgs e)
        {
 
 
            foreach (GridViewDataRowInfo row in grdClientes.Rows)
            {
                if (row.Cells["Seleccionado"].Value == "On")
                {
                    _selectedRowIndex += (int)row.Cells["Cantidad"].Value;
                }
            }
        }


Thanks in advance for your help.

1 Answer, 1 is accepted

Sort by
0
Stefan
Telerik team
answered on 20 Aug 2012, 12:39 PM
Hello David,

In the code provided, when some value in the grid changes, you are iterating all cells in a column in the grid and if their value is "On" you perform some operation. If this is what you need and you use GridViewCheckBoxColumn, you need to check if the value is true/false not "On". Here is a sample:
int _selectedRowIndex = 0;
void radGridView1_ValueChanged(object sender, EventArgs e)
{
    foreach (GridViewDataRowInfo row in radGridView1.Rows)
    {
        if (row.Cells["Bool"].Value != null && row.Cells["Bool"].Value != DBNull.Value && (bool)row.Cells["Bool"].Value == true)
        {
            _selectedRowIndex += (int)row.Cells["ID"].Value;
        }
    }
    this.Text = _selectedRowIndex.ToString();
}

If this is not your case, please elaborate a bit more on it and I will point you to the right direction.
 
All the best,
Stefan
the Telerik team
RadControls for WinForms Q2'12 release is now live! Check out what's new or download a free trial >>
Tags
GridView
Asked by
Juan
Top achievements
Rank 1
Answers by
Stefan
Telerik team
Share this question
or