我在XtraGrid中定义了以下列。该列包含强制用户选择3个选项之一的下拉列表。如何在每次用户更改下拉列表值时触发事件?
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;
答案 0 :(得分: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 :(得分: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
答案 2 :(得分:1)
将事件直接添加到存储库项目。
通过这种方式,您可以选择“下拉”事件,而不是列或单元格。
repositoryItem.EditValueChanged += new System.EventHandler(repositoryItem_EditValueChanged);