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

Disable Combobox based on a condition

1 Answer 178 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Alcatraz
Top achievements
Rank 1
Alcatraz asked on 12 May 2010, 10:37 AM
Hi Telerik team,

I have a scenario where in my gridview i need to show up combox for some cells and hide them for some other cells based on a
condition.

I tried this using Cell_formatting event using the following code but it doesnt seem to work fine.

 

private void radGridView2_CellFormatting(object sender, CellFormattingEventArgs e)

 

{

 

 

if (e.CellElement.ColumnInfo.HeaderText == "Amount" && customers.ToList<Customer>()[e.CellElement.RowIndex].Amount < 10 )

 

{

check =

true;

 

}

if

 

(this.radGridView2.Columns[e.CellElement.ColumnIndex].UniqueName == "Type1")

 

{

 

if (check)

 

{

((Telerik.WinControls.UI.

GridComboBoxCellElement)(e.CellElement)).Visibility = ElementVisibility.Hidden;

 

check =

false;

 

}

}


Here check is a class level boolean variable and I have a customer collection with 3 properties.  And the Type1 and Amount columns are dynamically added at runtime.

 

GridViewComboBoxColumn combo = new GridViewComboBoxColumn();

 

combo.HeaderText =

"Type1";

 

combo.UniqueName =

"Type1";

 

combo.DataSource =

this.BindData();

 

combo.DisplayMember =

"KeyValue";

 

combo.ValueMember =

"StringValue";

 

 

this.radGridView2.Columns.Add(combo);

 

 

 

GridViewTextBoxColumn data = new GridViewTextBoxColumn();

 

data.HeaderText =

"Amount";

 

data.UniqueName =

"Amount";

 

data.FieldName =

"Amount";

 

 

this.radGridView2.Columns.Add(data);

 



Kinldy help me  out in doing this.

Thanks
KrisYs

1 Answer, 1 is accepted

Sort by
0
Svett
Telerik team
answered on 15 May 2010, 01:02 PM
Hello Alcatraz,

You need to prevent the editor from showing for a specific cell depending on your conditions. You have to subscribe to CellBeginEdit event where you can cancel the edit mode. You can use the following code snippet:
private void radGridView_CellBeginEdit(object sender, GridViewCellCancelEventArgs e)
{
    e.Cancel = true;
}

All the best,
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.
Tags
GridView
Asked by
Alcatraz
Top achievements
Rank 1
Answers by
Svett
Telerik team
Share this question
or