2013-01-14 33 views
0

我在XtraGrid中定義了以下列。該列包含強制用戶選擇3個選項之一的下拉菜單。每次用戶更改下拉列表的值時,如何連線一個事件?如何在XtraGrid GridColumn中添加事件?

this.myCol.AppearanceCell.Options.UseTextOptions = true; 
this.myCol.AppearanceCell.TextOptions.HAlignment = 
    DevExpress.Utils.HorzAlignment.Near; 
this.myCol.Caption = "My Caption"; 
this.myCol.ColumnEdit = this._myRepositoryLookup; 
this.myCol.FieldName = "MyFieldName"; 
this.myCol.Name = "myId"; 
this.myCol.Visible = true; 
this.myCol.VisibleIndex = 5; 
this.myCol.Width = 252; 

回答

1

您可以訂閱任何RepositoryItemLookUpEdit Events,要使用這些庫項目控制工作,而提高。

根據您的要求,您應該使用RepositoryItem.EditValueChanged Event,它在更改編輯值後立即觸發。

注意

的EditValueChangedFiringMode屬性查找編輯 增量搜索過程中,而他們的彈出窗口打開被忽略。如果 編輯器的編輯值在增量搜索期間發生更改,則會立即觸發EditValueChanged事件。

代碼片段:

_myRepositoryLookup.EditValueChanged += new EventHandler(_myRepositoryLookup_EditValueChanged); 
this.myCol.AppearanceCell.Options.UseTextOptions = true; 
this.myCol.AppearanceCell.TextOptions.HAlignment = 
         DevExpress.Utils.HorzAlignment.Near; 
this.myCol.Caption = "My Caption"; 
this.myCol.ColumnEdit = this._myRepositoryLookup; 

LookupEdit事件處理方法

void _myRepositoryLookup_EditValueChanged(object sender, EventArgs e) 
{ 
    //your code here 
} 

如果你想分配編輯單個單元格,然後你可以使用GridView.CustomRowCellEdit Event

參考,可以幫助您:
DevExpress RepositoryItemLookUpEdit
Get Cell Control of GridView in DevExpress

1

你需要看看

GridView.CustomRowCellEdit事件或資源庫的項目事件

下面是使用DevExpress.XtraGrid.Views.Grid樣本

;

private void gridView1_CustomRowCellEdit(object sender, CustomRowCellEditEventArgs e) { 
    if (e.Column.FieldName == "FieldName") return; 
    GridView gv = sender as GridView; 
    string fieldName = gv.GetRowCellValue(e.RowHandle, gv.Columns["FieldName"]).ToString(); 
    switch (fieldName) { 
     case "Population": 
     e.RepositoryItem = repositoryItemSpinEdit1; 
     break; 
     case "Country": 
     e.RepositoryItem = repositoryItemComboBox1; 
     break; 
     case "Capital": 
     e.RepositoryItem = repositoryItemCheckEdit1; 
     break; 
    }   
} 

補充閱讀here

1

將事件直接添加到存儲庫項目。

通過這種方式,您可以從下拉菜單中選擇事件,而不是列或單元格。

repositoryItem.EditValueChanged += new System.EventHandler(repositoryItem_EditValueChanged); 
相關問題