錯誤:索引超出範圍必須爲非負數且小於集合的大小爲什麼我定製lookupEdit引發以下錯誤
我有一個自定義LookUpEdit -
public class MyLookUpEdit : LookUpEdit
我指到以下鏈接將MyLookUpEdit添加到功能區。現在MyLookUpEdit可用於我的ribbonPageGroup - >添加編輯器。
http://www.devexpress.com/Support/Center/KB/ViewKBIssue.aspx?kbid=A1237
這裏是MyLookUpEdit的InitializeControl方法:
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();
}
但在運行時,在絲帶,我不能按一下按鈕,看到所有可用值的lookupedit - 它看起來像彈出窗口是不公開的,當我離開的編輯,下面的代碼拋出錯誤:
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);
}
是的,這是一個解決方案。但另一個嚴重的問題是,當我點擊定製的lookupEdit時,我沒有看到任何下拉菜單。我跟蹤代碼,並且我看到數據源不是空的,它裏面有5條記錄。很困惑爲什麼會發生這種情況。甚至在控制初始化之後,我調用myLookUpEdit1.ShowPopUp();彈出窗口不顯示。我跟蹤到DevExpress代碼並查看屬性isPopUpOpen是否爲false,以便ShowPopUp返回。我怎樣才能將isPopUpOpen設置爲true? – spspli
我終於解決了這個問題!謝謝! – spspli