CheckBox Column Set based on Value in Text Field

6 posts, 0 answers
  1. Mark
    Mark avatar
    116 posts
    Member since:
    Oct 2014

    Posted 29 Jan 2018 Link to this post

    I want to have a check box column, that if there is test/value in column1, I want to check box to be checked.  If there isn't any value, I don't want it to be checked. What's easiest way to implement this?
  2. Dimitar
    Admin
    Dimitar avatar
    2598 posts

    Posted 30 Jan 2018 Link to this post

    Hi Mark,

    Once the grid is loaded you can iterate all rows and set the value. Then you will need to update it only when the other value is changed. Here is the code:
    protected override void OnLoad(EventArgs e)
    {
        base.OnLoad(e);
        foreach (GridViewRowInfo row in radGridView1.Rows)
        {
            if (row.Cells["Name"].Value == null || row.Cells["Name"].Value == DBNull.Value)
            {
                row.Cells["CheckBoxCol"].Value = false;
            }
            else
            {
                row.Cells["CheckBoxCol"].Value = true;
            }
        }
        radGridView1.CellValueChanged += RadGridView1_CellValueChanged;
    }
      
    private void RadGridView1_CellValueChanged(object sender, GridViewCellEventArgs e)
    {
        if (e.Column.Name == "Name")
        {
            if (e.Value == null || e.Value == DBNull.Value)
            {
                e.Row.Cells["CheckBoxCol"].Value = false;
            }
            else
            {
                e.Row.Cells["CheckBoxCol"].Value = true;
            }
        }
      
    }

    I hope this will be useful. Let me know if you have additional questions.

    Regards,
    Dimitar
    Progress Telerik
    Try our brand new, jQuery-free Angular components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
  3. Mark
    Mark avatar
    116 posts
    Member since:
    Oct 2014

    Posted 30 Jan 2018 in reply to Dimitar Link to this post

    This is ok, but I am data binding the grid.  I am then manually adding a checkboxgridcolumn after the binding and I want that check box to be checked if data in a field is not null and not empty.

  4. Dimitar
    Admin
    Dimitar avatar
    2598 posts

    Posted 31 Jan 2018 Link to this post

    Hello Mark,

    You can change the "if' statement like this:
    if (row.Cells["Name"].Value != null && row.Cells["Name"].Value.ToString() != String.Empty )
    {
        row.Cells["CheckBoxCol"].Value = false;
    }
    else
    {
        row.Cells["CheckBoxCol"].Value = true;
    }

    Should you have any other questions do not hesitate to ask.

    Regards,
    Dimitar
    Progress Telerik
    Try our brand new, jQuery-free Angular components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
  5. Mark
    Mark avatar
    116 posts
    Member since:
    Oct 2014

    Posted 31 Jan 2018 in reply to Dimitar Link to this post

    So, i have to manually update each row's checkbox column when I load the data?   I was hoping for something a little more automatic. 
  6. Dimitar
    Admin
    Dimitar avatar
    2598 posts

    Posted 01 Feb 2018 Link to this post

    Hi Mark,

    Another approach you can use is to create a custom function that checks for this and use it with expression column. Detailed information is available in the following articles:
    Should you have any other questions do not hesitate to ask.

    Regards,
    Dimitar
    Progress Telerik
    Try our brand new, jQuery-free Angular components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
Back to Top