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

Need help with GridViewCheckboxColumn

1 Answer 116 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Pieter Lourens
Top achievements
Rank 1
Pieter Lourens asked on 16 Mar 2010, 02:14 PM
Hi,

Please cen anyone help me with the following, I am trying to retrieve the values from a NewRow using the rowvalidated event, all is fine, the first time you add a new row

The second time you add a new row I am unable to get the values from the CheckBox Column

Is there any other way of doing this, am I doing it correctly??

I have attached the code for review

Thanks

Pieter
private void gridAddress_RowValidated(object sender, Telerik.WinControls.UI.RowValidatedEventArgs e)  
        {  
            if (e.Row is Telerik.WinControls.UI.GridViewNewRowInfo)  
            {  
                Telerik.WinControls.UI.GridViewDataRowInfo newRowInfo = (Telerik.WinControls.UI.GridViewDataRowInfo)((Telerik.WinControls.UI.GridViewNewRowInfo)e.Row).DataRowInfo;  
                //...    
                if (newRowInfo != null)  
                {  
                    CustomerAddress add = new CustomerAddress();  
 
                    add.CustomerID = currentitem.CustomerID;  
 
                    add.Addresstype = AddressTypes.AddressTypesByID(Convert.ToInt32(newRowInfo.Cells["AddressType"].Value));  
                    add.Address1 = newRowInfo.Cells["Address1"].Value.ToString();  
                    add.Address2 = newRowInfo.Cells["Address2"].Value.ToString();  
                    add.Suburb = newRowInfo.Cells["Suburb"].Value.ToString();  
                    add.City = newRowInfo.Cells["City"].Value.ToString();  
                    add.Zipcode = newRowInfo.Cells["ZipCode"].Value.ToString();  
                                                    
                    //if (newRowInfo.Cells["IsPrimary"].Value.Equals(true))  
                    //{  
                    //    add.IsPrimary = Convert.ToBoolean( newRowInfo.Cells["IsPrimary"].Value.ToString() );  
                    //}  
                    //else  
                    //{  
                    //    add.IsPrimary = false;  
                    //}  
                      
                    add.IsPrimary = Convert.ToBoolean(newRowInfo.Cells["IsPrimary"].Value.ToString());  
 
                    currentitem.CustomerAddress.Add(add);  
                }  
 
            }    
        } 

1 Answer, 1 is accepted

Sort by
0
Svett
Telerik team
answered on 18 Mar 2010, 05:02 PM
Hello Pieter Lourens,

You cannot access the value of the check box on RowValidating event when the active editor is the check box. This is because the value of the check box is not set as value of the cell. This happens after validation. So, you need to check whether the active editor is a check box. Further, you should take the value from the editor, but not form the cell.

You may adapt the following code snippet in your project:
void radGridView1_RowValidated(object sender, RowValidatedEventArgs e)
{
    if (e.Row is GridViewNewRowInfo)
    {
        GridViewNewRowInfo rowInfo = e.Row as GridViewNewRowInfo;
 
        RadCheckBoxEditor checkBox = this.radGridView1.ActiveEditor as RadCheckBoxEditor;
        bool checkBoxValue = Convert.ToBoolean(rowInfo.Cells["Bool"].Value);
 
        if (checkBox != null)
        {
            checkBoxValue = Convert.ToBoolean(checkBox.Value);
        }
 
    }
}

If you need further assistance, feel free to ask.

All the best,
Svett
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
Pieter Lourens
Top achievements
Rank 1
Answers by
Svett
Telerik team
Share this question
or