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-5656 CA Loves GCD(dp+数论)

    题目链接: CA Loves GCD Time Limit: 6000/3000 MS (Java/Others)     Memory Limit: 262144/262144 K (Java/Ot ...

  2. Ubuntu下安装deb包命令

    原文地址:http://www.xitongzhijia.net/xtjc/20150206/37464.html 1.下载需要安装的deb包,输入以下命令安装: sudo dpkg -i packa ...

  3. svn 操作手册

    1.执行下列指令安装    sudo apt-get install subversion   2.  创建版本库       sudo mkdir /home/svn    sudo mkdir / ...

  4. 误删除$ORACLE_HOME/dbs下的参数文件、密码文件,如何快速重建

    [oracle@11g dbs]$ pwd/home/oracle/app/oracle/product/11.2.0/dbhome_1/dbs[oracle@11g dbs]$ lltotal 24 ...

  5. The specified named connection is either not found in the configuration, not intended to be used

    今天用EF遇到一个问题, The specified named connection is either not found in the configuration, not intended t ...

  6. DataGridColum的bug

    Datagrid有多个bug: 1,不支持DynamicResource的东西 2, 在Column隐藏后再显示, ColumnHeader的Tag或者DataContext为null. 解决办法: ...

  7. 设置一个.exe文件开机启动

    运行"regedit",编辑注册表 HKEY_LOCAL_MACHINE -- SOFTWARE -- Microsoft -- Windows -- CurrentVersion ...

  8. nagios客户端安装与配置windows篇

    一.被监控的windows xp客户端的配置 1.安装NSClient++并安装下载地址: http://sourceforge.net/projects/nscplusNSClient++-0.3. ...

  9. H+ Se7en WebUI

    http://www.zi-han.net/theme/hplus/webim.html

  10. 继承HibernateDaoSupport实现DAO(spring整合hibernate)

    转自:https://blog.csdn.net/yz9612/article/details/80234377 spring为hibernate的DAO提供工具类:HibernateDaoSuppo ...