Unable to find control in RadGridView

5 posts, 1 answers
  1. Johny
    Johny avatar
    9 posts
    Member since:
    Nov 2009

    Posted 28 Mar 2010 Link to this post

    Hi

    I’m very new with the telerik, I’m trying to find a control from radGridview.I implements in .Net Grid control ( sample code is given below) But I cant do the same in radGridView. Can anyone give me any idea to implement this in radGridview. I need your help.

    Code snippets:

            foreach (GridViewRow row in dgrdInbox.Rows)

            {

              

                CheckBox cbBox = (CheckBox)row.FindControl("cbYesNo");

                 

               if (cbYesOrNo.Checked)

                {

                      // Do something

    }

    else

    {

    // Do something

    }

                        }

     

     

    Thanks in advanced. 

    Md. Marufuzzaman

  2. Svett
    Admin
    Svett avatar
    728 posts

    Posted 29 Mar 2010 Link to this post

    Hello Johny,

    Thank you for supplied code snippet.

    Presently, the controls in the suite do not use other controls to achieve their functionality. They use special elements of type RadElement.  It is the basic object in Telerik Presentation Framework used for implementation of RadControls for Winforms. You can read more about TPF in this documentation article.

    The fastest approach to get the desired value of specified column for each row is to go through the collection of Rows of the grid. You can use the following code snippet as sample:

    foreach (GridViewDataRowInfo dataRow in this.radGridView.Rows)
    {
        bool value = Convert.ToBoolean(dataRow.Cells["BoolColumn"].Value);
     
        if (value)
        {
            // TO DO: Your code when the value is true
        }
        else
        {
            // TO DO: Your code when the value is false
        }
    }

    If you have further questions feel free to write us back.

    Sincerely yours,
    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.
  3. UI for WinForms is Visual Studio 2017 Ready
  4. Johny
    Johny avatar
    9 posts
    Member since:
    Nov 2009

    Posted 29 Mar 2010 Link to this post

    Hi Svett:

    Thanks for your reply with sample code snippets, probably there is an issue of NULL value, this code will throw an exception when
    thedataRow.Cells["BoolColumn"].Value is NULL. Actually I'm facing an error that is (exception = {"Object cannot be cast from DBNull to other types."}). Any suggestion for this

    Thanks
    Md. Marufuzzaman
     

  5. Answer
    Svett
    Admin
    Svett avatar
    728 posts

    Posted 01 Apr 2010 Link to this post

    Hi Johny,

    Thank you for the clarification. You are receiving this exception because the Boolean cell for the specified row has a null value. Hence, .NET Framework Convert class throws exception. Therefore, you can modify the code snippet as it is shown below:
    foreach (GridViewDataRowInfo dataRow in this.radGridView.Rows)
    {
        bool value = false;
     
        if (dataRow.Cells["BoolColumn"].Value != null && !(dataRow.Cells["BoolColumn"].Value is DBNull))
        {
            value = Convert.ToBoolean(dataRow.Cells["BoolColumn"].Value);
        }
     
        if (value)
        {
            // TO DO: Your code when the value is true
        }
        else
        {
            // TO DO: Your code when the value is false
        }
    }

    If you need further assistance, do not hesitate to ask.

    Greetings,
    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.
  6. Johny
    Johny avatar
    9 posts
    Member since:
    Nov 2009

    Posted 01 Apr 2010 Link to this post

    Hi Svett:
        Thanks a lot :)

    Regards,
    Md. Marufuzzaman
Back to Top
UI for WinForms is Visual Studio 2017 Ready