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

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

4 Answers 30 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Free
Top achievements
Rank 1
Free asked on 27 Nov 2014, 11:42 AM
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 :)

4 Answers, 1 is accepted

Sort by
0
Dimitar
Telerik team
answered on 02 Dec 2014, 09:53 AM
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.

 
0
Free
Top achievements
Rank 1
answered on 02 Dec 2014, 04:47 PM
Thank you for your reply , but I want that the seconde column that name's "post" be fixed and dont clear text ? 
0
Accepted
Dimitar
Telerik team
answered on 05 Dec 2014, 01:53 PM
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.

 
0
Free
Top achievements
Rank 1
answered on 05 Dec 2014, 05:42 PM
Thank's Dimitar it was very helpful (y)
Tags
GridView
Asked by
Free
Top achievements
Rank 1
Answers by
Dimitar
Telerik team
Free
Top achievements
Rank 1
Share this question
or