How to set DateTimeColumn value to null when CheckBoxColumn is false??

5 posts, 1 answers
  1. Free
    Free avatar
    4 posts
    Member since:
    Nov 2014

    Posted 27 Nov 2014 Link to this post

    Hello everybody.
          -I'm new with telerik , I use Winforms q2 2014 sp1 , and I have a GridView ,that contains three column ,CheckBowColumn,DateTimeColumn and ComboBoxColumn , I want that when I Check a CheckBox the Columns Date and Combo be enabled , else the Text of Date and Combo cleared and disabled.
      How can I make this please ?? and thank's for help :)
  2. Dimitar
    Admin
    Dimitar avatar
    2686 posts

    Posted 02 Dec 2014 Link to this post

    Hello,

    Thank you for contacting us.

    The desired functionality can be achieved by using the the CellFormatting event:
    public Form1()
    {
        InitializeComponent();
        radGridView1.Columns.Add(new GridViewCheckBoxColumn("CheckBox") { EditMode = EditMode.OnValueChange });
        radGridView1.DataSource = GetTable();
        radGridView1.CellFormatting += radGridView1_CellFormatting;
    }
     
    void radGridView1_CellFormatting(object sender, Telerik.WinControls.UI.CellFormattingEventArgs e)
    {
        if (e.Column.Name != "CheckBox")
        {
            if (e.Row.Cells[0].Value != null && (bool)e.Row.Cells[0].Value )
            {
                e.CellElement.Enabled = true;
            }
            else
            {
                e.CellElement.Enabled = false;
                e.CellElement.Text = "";
            }
        }
    }

    More information about this event can be found here: Formatting Cells.

    Please let me know if there is something else I can help you with.

    Regards,
    Dimitar
    Telerik
     

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

     
  3. Free
    Free avatar
    4 posts
    Member since:
    Nov 2014

    Posted 02 Dec 2014 in reply to Dimitar Link to this post

    Thank you for your reply , but I want that the seconde column that name's "post" be fixed and dont clear text ? 
  4. Answer
    Dimitar
    Admin
    Dimitar avatar
    2686 posts

    Posted 05 Dec 2014 Link to this post

    Hi Free,

    Thank you for writing back.

    You can update the CellFormatting event and skip the text clearing for the second column:
    void radGridView1_CellFormatting(object sender, Telerik.WinControls.UI.CellFormattingEventArgs e)
    {
        if (e.Column.Name != "CheckBox")
        {
            if (e.Row.Cells[0].Value != null && (bool)e.Row.Cells[0].Value )
            {
                e.CellElement.Enabled = true;
            }
            else
            {
                e.CellElement.Enabled = false;
                if (e.Column.Name !="SecondColumnName")
                {
                    e.CellElement.Text = "";
                }
                 
            }
        }
    }

    Do not hesitate to contact us if you have other questions.
     
    Regards,
    Dimitar
    Telerik
     

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

     
  5. Free
    Free avatar
    4 posts
    Member since:
    Nov 2014

    Posted 05 Dec 2014 in reply to Dimitar Link to this post

    Thank's Dimitar it was very helpful (y)
Back to Top