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