Search website

How to attach a comboedit to grid column

The following sample code illustrates how to attach a comboedit to a grid column. The following code is written to work in the Invoice Entry window. As this sample shows more on how to use the DevExpress UI component, please navigate to the DevExpress documentation website for more information.

Code Snippet
  1. private DevExpress.XtraEditors.Repository.RepositoryItemComboBox myDescComboBox;
  2. ///<summary>
  3. /// Use this event to do form initialization
  4. ///</summary>
  5. ///<param name=”e”>The event argument</param>
  6. public void OnFormInitialize(BCE.AutoCount.Invoicing.Sales.Invoice.FormInvoiceEntry.FormInitializeEventArgs e)
  7. {
  8.     myDescComboBox = new DevExpress.XtraEditors.Repository.RepositoryItemComboBox();
  9.     e.GridControl.RepositoryItems.Add(myDescComboBox);
  10.     DevExpress.XtraGrid.Views.Grid.GridView gv = (DevExpress.XtraGrid.Views.Grid.GridView)e.GridControl.MainView;
  11.     gv.FocusedRowChanged += new DevExpress.XtraGrid.Views.Base.FocusedRowChangedEventHandler(gv_FocusedRowChanged);
  12.     gv.FocusedColumnChanged += new DevExpress.XtraGrid.Views.Base.FocusedColumnChangedEventHandler(gv_FocusedColumnChanged);
  13. }
  14. void gv_FocusedColumnChanged(object sender, DevExpress.XtraGrid.Views.Base.FocusedColumnChangedEventArgs e)
  15. {
  16.     DevExpress.XtraGrid.Views.Grid.GridView gv = sender as DevExpress.XtraGrid.Views.Grid.GridView;
  17.     if (e.FocusedColumn.FieldName == “Description”)
  18.     {
  19.         System.Data.DataRow row = gv.GetDataRow(gv.FocusedRowHandle);
  20.         if (row != null)
  21.         {
  22.             string itemCode = row[“ItemCode”].ToString();
  23.             if (itemCode == “LG110″)
  24.             {
  25.                 Fill_LG110_Selection();
  26.                 e.FocusedColumn.ColumnEdit = myDescComboBox;
  27.             }
  28.             elseif (itemCode == “LG200″)
  29.             {
  30.                 Fill_LG200_Selection();
  31.                 e.FocusedColumn.ColumnEdit = myDescComboBox;
  32.             }
  33.             else
  34.                 e.FocusedColumn.ColumnEdit = null;
  35.         }
  36.         else
  37.             e.FocusedColumn.ColumnEdit = null;
  38.     }
  39. }
  40. void gv_FocusedRowChanged(object sender, DevExpress.XtraGrid.Views.Base.FocusedRowChangedEventArgs e)
  41. {
  42.     DevExpress.XtraGrid.Views.Grid.GridView gv = sender as DevExpress.XtraGrid.Views.Grid.GridView;
  43.     System.Data.DataRow row = gv.GetDataRow(gv.FocusedRowHandle);
  44.     if (row != null)
  45.     {
  46.         string itemCode = row[“ItemCode”].ToString();
  47.         if (itemCode == “LG110″)
  48.         {
  49.             Fill_LG110_Selection();
  50.             gv.Columns[“Description”].ColumnEdit = myDescComboBox;
  51.         }
  52.         elseif (itemCode == “LG200″)
  53.         {
  54.             Fill_LG200_Selection();
  55.             gv.Columns[“Description”].ColumnEdit = myDescComboBox;
  56.         }
  57.         else
  58.             gv.Columns[“Description”].ColumnEdit = null;
  59.     }
  60.     else
  61.         gv.Columns[“Description”].ColumnEdit = null;
  62. }
  63. void Fill_LG110_Selection()
  64. {
  65.     myDescComboBox.Items.Clear();
  66.     myDescComboBox.Items.AddRange(newobject[] { “LG110-001″, “LG110-002″, “LG110-003″ });
  67. }
  68. void Fill_LG200_Selection()
  69. {
  70.     myDescComboBox.Items.Clear();
  71.     myDescComboBox.Items.AddRange(newobject[] { “LG200-001″, “LG200-002″, “LG200-003″, “LG200-004″ });
  72. }