using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Linq;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using DevExpress.XtraEditors.Repository; namespace Thread {
public partial class XtraForm1 : DevExpress.XtraEditors.XtraForm {
private IList<Order> list = null;
private IList<OrderGoods> orderGoods = null;
public XtraForm1() {
InitializeComponent();
list = GetOrders();
orderGoods = GetOrderGoods();
} private IList<Order> GetOrders() {
var list = new List<Order>();
list.Add(new Order { OrderNo = "A001", Rearmk = "Rearmk1" });
list.Add(new Order { OrderNo = "A002", Rearmk = "Rearmk2" });
list.Add(new Order { OrderNo = "A003", Rearmk = "Rearmk3" });
return list;
} private IList<OrderGoods> GetOrderGoods() {
var list = new List<OrderGoods>();
list.Add(new OrderGoods { OrderNo = "A001", Qty = , GoodsNo = "G01" });
list.Add(new OrderGoods { OrderNo = "A001", Qty = , GoodsNo = "G02" });
list.Add(new OrderGoods { OrderNo = "A001", Qty = , GoodsNo = "G03" }); list.Add(new OrderGoods { OrderNo = "A002", Qty = , GoodsNo = "G04" });
list.Add(new OrderGoods { OrderNo = "A002", Qty = , GoodsNo = "G05" });
list.Add(new OrderGoods { OrderNo = "A002", Qty = , GoodsNo = "G06" }); list.Add(new OrderGoods { OrderNo = "A003", Qty = , GoodsNo = "G07" });
list.Add(new OrderGoods { OrderNo = "A003", Qty = , GoodsNo = "G08" });
list.Add(new OrderGoods { OrderNo = "A003", Qty = , GoodsNo = "G09" }); return list;
} private void XtraForm1_Load(object sender, EventArgs e) {
this.gridControl1.DataSource = list;
} private void gridView1_RowClick(object sender, DevExpress.XtraGrid.Views.Grid.RowClickEventArgs e) { } private void gridControl1_Click(object sender, EventArgs e) {
} DataTable table; private void gridView1_FocusedRowChanged(object sender, DevExpress.XtraGrid.Views.Base.FocusedRowChangedEventArgs e) {
var order = gridView1.GetFocusedRow() as Order;
table = GetOrderGoodsTable(order.OrderNo);
this.gridControl2.DataSource = table;
} private DataTable GetOrderGoodsTable(string gNo) { if (gNo == "A001") {
table = new DataTable("CartonExTemp");
table.Columns.Add(new DataColumn("GoodsNo", typeof(string)));
table.Columns.Add(new DataColumn("X", typeof(int)));
table.Columns.Add(new DataColumn("M", typeof(int)));
table.Columns.Add(new DataColumn("L", typeof(int)));
table.Rows.Add("G001", , , );
table.Rows.Add("G002", , , );
table.Rows.Add("G003", , , );
}
else if (gNo == "A002") {
table = new DataTable("CartonExTemp");
table.Columns.Add(new DataColumn("GoodsNo", typeof(string)));
table.Columns.Add(new DataColumn("", typeof(int)));
table.Columns.Add(new DataColumn("", typeof(int)));
table.Rows.Add("G003", , );
table.Rows.Add("G004", , );
table.Rows.Add("G005", , );
}
else { table = new DataTable("CartonExTemp");
table.Columns.Add(new DataColumn("GoodsNo", typeof(string)));
table.Columns.Add(new DataColumn("", typeof(int)));
table.Columns.Add(new DataColumn("", typeof(int)));
table.Rows.Add("G003", , );
table.Rows.Add("G004", , );
table.Rows.Add("G005", , );
}
return table;
} private void gridView2_DataSourceChanged(object sender, EventArgs e) {
gridView2.Columns.Clear();
foreach (DataColumn dc in table.Columns) {
var gridColumn1 = gridView2.Columns.AddVisible(dc.ColumnName);
if (dc.ColumnName == "GoodsNo") {
gridColumn1.Caption = "货号";
gridColumn1.OptionsColumn.AllowEdit = false;
gridColumn1.Width = ;
}
else {
gridColumn1.ColumnEdit = new RepositoryItemSpinEdit();
}
}
gridView2.BestFitColumns();
} } public class Order {
public string OrderNo { get; set; }
public string Rearmk { get; set; }
} public class OrderGoods {
public string GoodsNo { get; set; }
public int Qty { get; set; }
public string OrderNo { get; set; }
}
}

回车事件,转到下一可编辑的单元格

  private void gridView1_KeyDown(object sender, KeyEventArgs e) {
GridView grid = sender as GridView; if (e.KeyCode == Keys.Enter) {
int focusedRowHandle = grid.FocusedRowHandle; int index = GetNextIndex(grid);
this.Text = string.Format("index={0},grid.FocusedColumn.VisibleIndex={1}", index, grid.FocusedColumn.VisibleIndex);
if (index == grid.VisibleColumns.Count - ) {
focusedRowHandle++;
}
BeginInvoke(new MethodInvoker(() => {
grid.FocusedRowHandle = focusedRowHandle;
grid.FocusedColumn = grid.VisibleColumns[index];
grid.ShowEditor();
})); }
}

DevExpress GridControl 控件二表连动的更多相关文章

  1. DevExpress GridControl控件行内新增、编辑、删除添加选择框

    以下为内容以图片居多1234表示点击顺序 先新增一行 操作和新增数据行一样 打开ColumnEdit  选择new ButtenEdit  new上方会出现一个系统命名的button 命名可以更改必须 ...

  2. DevExpress GridControl控件行内新增、编辑、删除添加选择框(转)

    http://blog.csdn.net/m1654399928/article/details/21951519 1.首先到GridControl控件设计里设置属性Repository    (In ...

  3. 设置DevExpress GridControl控件时间列显示时、分、秒样式

    如题,如果Dev GridControl控件绑定DataTable数据源时,DataTable中的某一列为Date类型时,GridControl默认显示样式只显示当前日期,并不会将时.分.秒显示出来. ...

  4. DevExpress GridControl 控件点滴

    一.常用控件样式 public void setDgv(DevExpress.XtraGrid.Views.Grid.GridView gridView1) { gridView1.OptionsVi ...

  5. DevExpress gridControl控件动态绑定列 zt

    DataTable dt = =Query.GetCustome=(ref customColumnCount); //绑定列 gridView.Columns.Add(}); gridView.Co ...

  6. DevExpress之GridControl控件小知识

    DevExpress之GridControl控件小知识 一.当代码中的DataTable中有建数据关系时,DevExpress 的 GridControl 会自动增加一个子视图 .列名也就是子表的字段 ...

  7. DevExpress控件的GridControl控件小结

    DevExpress控件的GridControl控件小结 (由于开始使用DevExpress控件了,所以要点滴的记录一下) 1.DevExpress控件组中的GridControl控件不能使横向滚动条 ...

  8. DevExpress的GridControl控件更新數據問題解決辦法

    開發WPF程序時,使用Devexpress的GridControl控件用ItemSource綁定數據,在頁面進行編輯時,當屬性繼承INotifyPropertyChanged接口時會同步更新後臺數據. ...

  9. 【转】Devexpress使用之:GridControl控件(合并表头)

    Devexpress系列控件功能很强大,使用起来也不太容易,我也是边摸索边使用,如果有时间我会把常用控件的使用方法整理出来的. using System; using System.Collectio ...

随机推荐

  1. hdu-5826 physics(数学)

    题目链接: physics Time Limit: 6000/3000 MS (Java/Others)     Memory Limit: 65536/65536 K (Java/Others) P ...

  2. 理解YOLOv2训练过程中输出参数含义

    原英文地址: https://timebutt.github.io/static/understanding-yolov2-training-output/ 最近有人问起在YOLOv2训练过程中输出在 ...

  3. 关闭windows10自动更新

    用windows10的小伙伴们应该都被windows10自动更新这个问题折磨过.那到底要这样禁止windows10的自动更新呢? 百度上有一篇文章写的非常好,并且有配套,大家只要根据步骤操作即可,本人 ...

  4. BZOJ1382:[Baltic2001]Mars Maps

    浅谈树状数组与线段树:https://www.cnblogs.com/AKMer/p/9946944.html 题目传送门:https://www.lydsy.com/JudgeOnline/prob ...

  5. hdu3037Saving Beans——卢卡斯定理

    题目:http://acm.hdu.edu.cn/showproblem.php?pid=3037 卢卡斯定理模板——大组合数的取模 代码如下: #include<iostream> #i ...

  6. poj3208启示录——数位DP

    题目:http://poj.org/problem?id=3208 数位DP,首先按位数预处理出每一种位数的情况,包括有多少个魔鬼数和有多少个以6开头的非魔鬼数,以便递推.累加等等: 然后先找出第X个 ...

  7. C# 线程的暂停和恢复的 实现

    我们可以通过ManualResetEvent类来实现. 声明, 初始化时不执行 private static ManualResetEvent _eventWorkList = new ManualR ...

  8. Poj_1088_滑雪(DP)

    一.Description(poj1088) Michael喜欢滑雪百这并不奇怪,  因为滑雪的确很刺激.可是为了获得速度,滑的区域必须向下倾斜,而且当你滑到坡底,你不得不再次走上坡或者等待升降机来载 ...

  9. 水题 等差数列HDU 5400 Arithmetic Sequence

    主要是要知道它对于等差数列的定义,单个数也可以作为等差数列且一定满足题意,另外就是要算清楚区间与区间的关系,考虑两大类情况,一种是d1区间和d2区间连在一起,另外一种情况就是其余情况. #includ ...

  10. Django admin有用的自定义功能

    引用园友 无名小妖 的博客 https://www.cnblogs.com/wumingxiaoyao/p/6928297.html 写的很好,但是博客园不能转载,不过我已经点赞了~