Hi all,
i have a problem with my custom edit column template.
This is my column
All works fine, but when i edit an existing item, the selected item displayed on combobox is not the current value.
The SelectedIndex is correctly but the displayed item is always the first.
Any suggestion?
Thanks in advance,
Flavio
i have a problem with my custom edit column template.
This is my column
public class MyEnumColumnEditor : GridTextColumnEditor |
{ |
private RadComboBox box; |
private readonly Type enumType; |
private readonly bool useDescription = false; |
private readonly bool addTopEmptyItem = false; |
public MyEnumColumnEditor(Type enumType, bool useDescription, bool addTopEmptyItem) |
{ |
this.enumType = enumType; |
this.useDescription = useDescription; |
this.addTopEmptyItem = addTopEmptyItem; |
} |
protected override void AddControlsToContainer() |
{ |
this.box = new RadComboBox(); |
ArrayList list = new ArrayList(); |
Array enumValues = Enum.GetValues(enumType); |
Type baseType = Enum.GetUnderlyingType(enumType); |
if (addTopEmptyItem) |
list.Add(new KeyValuePair<int, string>(-1, string.Empty)); |
foreach (Enum value in enumValues) |
{ |
string desc = useDescription ? Data.GetEnumDescription(value) : value.ToString(); |
list.Add(new KeyValuePair<int, string>((int)Convert.ChangeType(value, baseType), desc)); |
} |
this.box.DataSource = list; |
this.box.DataTextField = "Value"; |
this.box.DataValueField = "Key"; |
this.box.DataBind(); |
this.box.SelectedIndex = 0; |
this.ContainerControl.Controls.Add(this.box); |
} |
protected override void LoadControlsFromContainer() |
{ |
this.box = this.ContainerControl.Controls[0] as RadComboBox; |
} |
public override bool IsInitialized |
{ |
get |
{ |
return this.box != null; |
} |
} |
public override string Text |
{ |
get |
{ |
if (this.box.SelectedItem == null) |
return string.Empty; |
return this.box.SelectedValue; |
} |
set |
{ |
this.box.SelectedIndex = string.IsNullOrEmpty(value) ? 0 : |
this.box.FindItemIndexByValue(value); |
} |
} |
} |
All works fine, but when i edit an existing item, the selected item displayed on combobox is not the current value.
The SelectedIndex is correctly but the displayed item is always the first.
Any suggestion?
Thanks in advance,
Flavio