Pergunta

I have the following column defined inside of an XtraGrid. The column consists of dropdowns that force a user to choose one of 3 options. How can I wire an event that fires each time a user changes the value of a dropdown?

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;
Foi útil?

Solução

You can subscribe to any RepositoryItemLookUpEdit Events, that you want to raise while working with these repository item controls.

For your requirement, you should use RepositoryItem.EditValueChanged Event, it Fires immediately after changing the edit value.

Note

The EditValueChangedFiringMode property is ignored for lookup editors during an incremental search while their popup windows are open. If the editor's edit value is changed during an incremental search, the EditValueChanged event fires immediately.

Code snippet:

_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 event handler method

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

If you want to assign editors to individual cells then you can use GridView.CustomRowCellEdit Event

References that may help you:
DevExpress RepositoryItemLookUpEdit
Get Cell Control of GridView in DevExpress

Outras dicas

You need to look at

GridView.CustomRowCellEdit Event or Repository Items Event

Here is a sample

using 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;
   }           
}

Additional reading here

Add an event directly to the Repository Item.

That way you can choose from the events of a Drop Down and not a column or cell.

repositoryItem.EditValueChanged += new System.EventHandler(repositoryItem_EditValueChanged);
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top