RepositoryItemGridLookUpEdit 使用 ok




private void Form1_Load(object sender, EventArgs e)
  {

      下拉初始化();
      gridControl1.DataSource = DemoData.GetGridData();
  }

  private void 下拉初始化()
  {
      GridView view = rep_Grid.View;
      view.Columns.Add(new GridColumn { Caption = "货号", FieldName = "GoodsNo", Width = 100, VisibleIndex = 0 });
      view.Columns.Add(new GridColumn { Caption = "品名", FieldName = "ProductName", Width = 200, VisibleIndex = 1 });
      view.Columns.Add(new GridColumn { Caption = "客户", FieldName = "CustomerName", Width = 100, VisibleIndex = 2 });

      rep_Grid.PopupFormSize = new Size(450, 300);//下拉窗体尺寸
      rep_Grid.AcceptEditorTextAsNewValue = DevExpress.Utils.DefaultBoolean.True; //重要!!!接受文本框的值作为新值显示
      rep_Grid.View.RowHeight = 22; //行高
      rep_Grid.ImmediatePopup = true;//输入值立即弹出下拉窗体
      rep_Grid.SearchMode = GridLookUpSearchMode.AutoSearch;//设置为自动搜索模式,重要!!!
      rep_Grid.PopupFilterMode = DevExpress.XtraEditors.PopupFilterMode.Contains;//表格筛选列过滤模式
      rep_Grid.TextEditStyle = DevExpress.XtraEditors.Controls.TextEditStyles.Standard;//允许录入资料
      rep_Grid.View.OptionsView.ShowAutoFilterRow = true;//下拉表格显示过滤行

      //绑定下拉窗体数据源
      rep_Grid.DataSource = DemoData.GetGoodsList();
      rep_Grid.EditValueChanged += rep_Grid_EditValueChanged;
      //rep_Grid.ProcessNewValue += OnGrid_ProcessNewValue; //在输入框录入新值处理事件
      //                                                    //按回车键处理包含关系的新值
      //rep_Grid.KeyDown += On_GridLookUpEdit_KeyDown;

      ////下拉表格的记录行点击事件
      //rep_Grid.View.RowClick += On_GridLookUpEdit_RowClick;           

      rep_Grid.DisplayMember = "GoodsNo";
      rep_Grid.ValueMember = "GoodsNo";
  }

  private void rep_Grid_EditValueChanged(object sender, EventArgs e)
  {
      GridLookUpEdit LookupEdit = sender as GridLookUpEdit;
      GoodsItem SelectedDataRow = (GoodsItem)LookupEdit.GetSelectedDataRow();
      gridView1.SetFocusedRowCellValue("ProductName", SelectedDataRow.ProductName);
      gridView1.SetFocusedRowCellValue("Qty", SelectedDataRow.Qty);
  }





using System.Collections.Generic;

internal class DemoData
{
    /// <summary>
    /// 表格数据源
    /// </summary>
    /// <returns></returns>
    public static List<GoodsItem> GetGridData()
    {
        var result = new List<GoodsItem>()
            {
                new GoodsItem{ GoodsNo="G001", ProductName="鼠标01", Qty=200 },
                new GoodsItem{ GoodsNo="G=A01", ProductName="键盘102", Qty=105 },
                new GoodsItem{ GoodsNo="Xa-99", ProductName="机箱GameBox", Qty=100 },
            };
        return result;
    }

    /// <summary>
    /// 表格下拉窗体数据源
    /// </summary>
    /// <returns></returns>
    public static List<GoodsItem> GetGoodsList()
    {
        var result = new List<GoodsItem>()
            {
                new GoodsItem{ CustomerName="联想", GoodsNo="G001", ProductName="鼠标01", Qty=200 },
                new GoodsItem{ CustomerName="ASUS",GoodsNo="A=AC01", ProductName="键盘102", Qty=105 },
                new GoodsItem{ CustomerName="DELL",GoodsNo="D9B9", ProductName="键盘102", Qty=100 },
                new GoodsItem{ CustomerName="ACER",GoodsNo="AXa001", ProductName="机箱GameBox", Qty=100 },
                new GoodsItem{ CustomerName="ACER",GoodsNo="AX8B70", ProductName="键盘A102", Qty=100 },
                new GoodsItem{ CustomerName="联想",GoodsNo="GXzC", ProductName="鼠标A01", Qty=100 },
                new GoodsItem{ CustomerName="ASUS",GoodsNo="AXa99B", ProductName="机箱GameBox", Qty=100 },
                new GoodsItem{ CustomerName="联想",GoodsNo="GXa2", ProductName="鼠标B01", Qty=100 },
            };
        return result;
    }

}

public class GoodsItem
{
    public string CustomerName { get; set; }
    public string ProductName { get; set; }
    public string GoodsNo { get; set; }
    public int Qty { get; set; }

}





image

posted @ 2025-09-17 13:38  网络来者  阅读(24)  评论(0)    收藏  举报