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

How to make Gridviewcomboboxcolumn item not selectable

1 Answer 291 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Uday
Top achievements
Rank 1
Uday asked on 27 Jun 2012, 10:00 AM
hi telerik,

how to make Gridviewcombobox column element not selectable based on some condition, and also how to set that element background colour to some other colour(like gray).


Thanks

Uday

1 Answer, 1 is accepted

Sort by
0
Stefan
Telerik team
answered on 02 Jul 2012, 07:52 AM
Hi Uday,

Thank you for writing.

The correct place to disable a CellElement is the CellFormatting event. Here is a small sample demonstrating how to do that upon some condition:
public Form1()
{
    InitializeComponent();
    GridViewDecimalColumn c = new GridViewDecimalColumn("id");
    radGridView1.Columns.Add(c);
 
    GridViewComboBoxColumn col = new GridViewComboBoxColumn("combo col");
    radGridView1.Columns.Add(col);
    col.DataSource = new string[] { "asd", "qwe", "zxc" };
    radGridView1.Rows.Add(1, "asd");
    radGridView1.Rows.Add(2, "qwe");
    radGridView1.Rows.Add(3, "zxc");
 
    radGridView1.CellFormatting += new CellFormattingEventHandler(radGridView1_CellFormatting);
}
 
void radGridView1_CellFormatting(object sender, CellFormattingEventArgs e)
{
    if (e.Column.Name == "combo col" && Convert.ToInt32(e.Row.Cells["id"].Value) == 2)
    {
        e.CellElement.Enabled = false;
        e.CellElement.DrawFill = true;
    }
    else
    {
        e.CellElement.ResetValue(LightVisualElement.EnabledProperty, Telerik.WinControls.ValueResetFlags.Local);
        e.CellElement.ResetValue(LightVisualElement.DrawFillProperty, Telerik.WinControls.ValueResetFlags.Local);
    }
}

More information regarding the capabilities of the CellFormatting event can be found here:  http://www.telerik.com/help/winforms/gridview-cells-formatting-cells.html.

I hope this helps.
 
Kind regards,
Stefan
the Telerik team
RadControls for WinForms Q2'12 release is now live! Check out what's new or download a free trial >>
Tags
GridView
Asked by
Uday
Top achievements
Rank 1
Answers by
Stefan
Telerik team
Share this question
or