Why my customized lookupEdit throw the following error
-
30-10-2019 - |
Question
Error: Index was out of range Must be non-negative and less than the size of the collection
I have a customized LookUpEdit -
public class MyLookUpEdit : LookUpEdit
I refer to the following link to add MyLookUpEdit to a ribbon. Now MyLookUpEdit is available in my ribbonPageGroup-->Add Editor.
http://www.devexpress.com/Support/Center/KB/ViewKBIssue.aspx?kbid=A1237
Here is the InitializeControl Method for MyLookUpEdit:
public void InitializeControl(ICollection cache, string columnField1, string columnField2, string valueField, bool isMultiColumn, int searchColumn)
{
Properties.ForceInitialize();
const int maxDropDownSize = 7;
Properties.Columns.Clear();
if(isMultiColumn)
{
Properties.Columns.AddRange(new[] {
new LookUpColumnInfo(columnField1, columnField1, columnField1.Length*6, FormatType.None, "", true, HorzAlignment.Near, DevExpress.Data.ColumnSortOrder.None),
new LookUpColumnInfo(columnField2, columnField2, 100, FormatType.None, "", true , HorzAlignment.Near, DevExpress.Data.ColumnSortOrder.None)});
Properties.ShowHeader = true;
Properties.PopupFormMinSize = new Size(0, 0);
Properties.AppearanceDropDownHeader.TextOptions.HAlignment = HorzAlignment.Near;
Properties.AutoSearchColumnIndex = searchColumn;
}
else
{
Properties.Columns.AddRange(new[]{
new LookUpColumnInfo(columnField1, columnField1, 10, FormatType.None, "", true, HorzAlignment.Near, DevExpress.Data.ColumnSortOrder.None),
new LookUpColumnInfo(columnField2, columnField2, 0, FormatType.None, "", false , HorzAlignment.Near, DevExpress.Data.ColumnSortOrder.None)});
Properties.ShowHeader = false;
Properties.PopupFormMinSize = new Size(10, 10); // set popup width to control width
break;
}
Properties.ShowFooter = false;
Properties.ShowLines = true;
Properties.ValueMember = valueField;
Properties.DisplayMember = columnField1;
Properties.DataSource = cache;
if (cache == null) return;
Properties.DropDownRows = cache.Count > maxDropDownSize ? maxDropDownSize : cache.Count;
ColumnBestFit();
HideIcon();
}
But at the run time, in ribbon, I cannot click the button and see all available values for the lookupedit - it looks like the popup is not open, and when I leave the edit, the following code throw the error:
protected override void OnLeave(EventArgs e)
{
if (IsPopupOpen)
{
ItemIndex = PopupForm.SelectedIndex;
_selectfromPopup = true;
}
Properties.DisplayMember = Properties.Columns[0].Caption; // This line throw the error
base.OnLeave(e);
if (textChanged)
OnLeaveWithChangedText(e);
}
No correct solution
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow