惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

J
Java Code Geeks
Stack Overflow Blog
Stack Overflow Blog
B
Blog RSS Feed
C
Check Point Blog
D
Docker
Y
Y Combinator Blog
Recent Announcements
Recent Announcements
Google DeepMind News
Google DeepMind News
MongoDB | Blog
MongoDB | Blog
博客园_首页
Apple Machine Learning Research
Apple Machine Learning Research
量子位
有赞技术团队
有赞技术团队
IT之家
IT之家
大猫的无限游戏
大猫的无限游戏
D
DataBreaches.Net
M
MIT News - Artificial intelligence
B
Blog
阮一峰的网络日志
阮一峰的网络日志
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
腾讯CDC
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
V
V2EX
月光博客
月光博客

博客园 - 网络来者

Element Plus 多页面后台与 ASP.NET Core API 从零手敲教程 从零创建 MESTOOLS 消息弹窗跟练教程 uni app开发一个子页面 MES物料分摊 墨西哥 嘉兴 兼容车牌摄像头 和 tplink 摄像头的sdk开发包 集成 训练数字识别模型 tplink摄像头监控 mes测试机 redis vue学习 vue 系统文件结构 udp server 监听服务 第一个服务 c# 开发相关 openclaw 安装 c# 版本号 oracle 触发器 脚本方式安装Python 特定版本 idea 激活 Chrome MCP Server mcp ok mcp_server devexpress gridcontrol表格知识 winfrom 弹文本框 松下贴片机解锁 Serilog日志组件使用 git 使用
RepositoryItemGridLookUpEdit 使用 ok
网络来者 · 2025-09-17 · via 博客园 - 网络来者
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