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