Dev GridControl 主从表,数据加载,数据获取,单个从表获取 ,主从表单元格光标跳转
作者:互联网
描述 :首先明白主从表的关系 可以直接理解成 1对多的关系主表一行对应一个子表
1 .数据加载
界面:如图新建两个VIew
绑定数据 GrcDetail.DataSource = ShowModes; list<model> 的集合
PlanTargeEditViewModel md = new PlanTargeEditViewModel() { TargetId = list.Id, Id = planId, Color = list.Color, Level = list.Level, UnitOfMeasureMent = list.UnitOfMeasurement.ToString(), Count = list.Count, Price = list.Price, WarehoueName = list.WarehouseName, MaterialName = list.MaterialName, Specification = list.Specification, ProcessingCharges = list.ProcessingCharges, FinalPrice = Upf.BackColor == Color.LimeGreen ? ((list.ConfirmPrice == 0) ? 0 : list.ConfirmPrice) : null, ConfirmPrice = (totalprice + decimal.Parse(string.IsNullOrEmpty(list.ProcessingCharges.ToString()) ? "0" : list.ProcessingCharges.ToString())).ToString(), SegmentList = upstreamListlist, }; ShowModes.Add(md);
GrcDetail.DataSource = ShowModes;
SegmentList 这个是子表list<model>的集合,这个名称得写对
2.数据获取
1.直接获取数据源用于保存整表 datasources获取不解释
2.主表相关事件中获取子表
private void Grv01_KeyDown(object sender, KeyEventArgs e) { if (e.KeyData == Keys.Enter && pri != 0) { if (Grv01.FocusedColumn == MProcessingCharges) { var view = (GridView)GrcDetail.FocusedView;//获取当前焦点所在的view GridView child = (GridView)view.GetDetailView(view.FocusedRowHandle, view.GetRelationIndex(view.FocusedRowHandle, "SegmentList"));
//GetDetailView(主表行index,子表行index) getrelationindex 获取子表的索引(主表index,"子表名称") if (child !=null && child.RowCount > 0) { child.FocusedRowHandle = 0; child.FocusedColumn = child.Columns["Price"]; BeginInvoke(new Action(() => { child.ShowEditor(); })); } } if (Grv01.FocusedColumn == MFinalPrice) { var view = (GridView)GrcDetail.FocusedView; int index = view.FocusedRowHandle; int RowCount = Grv01.RowCount - 1; if (index < RowCount) { view.FocusedRowHandle = index + 1; view.FocusedColumn = view.Columns["ProcessingCharges"]; BeginInvoke(new Action(() => { view.ShowEditor(); })); } } } }
3.子表中获取主表就简单了 主表有FocusedRowHandle ,子表也有FocusedRowHandle 这俩不冲突 所以GetRowCellValue直接取就行了
3.回车主子表跳转
想:1.这是俩操作主表跳子表主view,kewdown
private void Grv01_KeyDown(object sender, KeyEventArgs e) { if (e.KeyData == Keys.Enter && pri != 0) { if (Grv01.FocusedColumn == MProcessingCharges) { var view = (GridView)GrcDetail.FocusedView; GridView child = (GridView)view.GetDetailView(view.FocusedRowHandle, view.GetRelationIndex(view.FocusedRowHandle, "SegmentList")); if (child !=null && child.RowCount > 0) { child.FocusedRowHandle = 0; child.FocusedColumn = child.Columns["Price"]; BeginInvoke(new Action(() => { child.ShowEditor(); })); } } if (Grv01.FocusedColumn == MFinalPrice) { var view = (GridView)GrcDetail.FocusedView; int index = view.FocusedRowHandle; int RowCount = Grv01.RowCount - 1; if (index < RowCount) { view.FocusedRowHandle = index + 1; view.FocusedColumn = view.Columns["ProcessingCharges"]; BeginInvoke(new Action(() => { view.ShowEditor(); })); } } } }
2.子表到主表 子表view,keydown
private void PlanSources_KeyDown(object sender, KeyEventArgs e) { if (e.KeyData == Keys.Enter && pri != 0) { var view = (GridView)GrcDetail.FocusedView; int DetailIndex = view.FocusedRowHandle; int RowCount = view.RowCount - 1; int MainIndex = Grv01.FocusedRowHandle; if (DetailIndex < RowCount) { view.FocusedRowHandle = DetailIndex + 1; view.FocusedColumn = view.Columns["Price"]; BeginInvoke(new Action(() => { view.ShowEditor(); })); } else { BeginInvoke(new Action(() => { view.ShowEditor(); })); Grv01.FocusedRowHandle = MainIndex; Grv01.FocusedColumn = Grv01.Columns["FinalPrice"]; BeginInvoke(new Action(() => { Grv01.ShowEditor(); })); } } }
其他:BeginInvoke(new Action(() => { view.ShowEditor(); })); 这个我理解的就是 更新设置的意思可能理解的不对,改了哪个view 的设置就更新哪个
亲测绝对有效 都给人客户弄上了
标签:FocusedRowHandle,RowCount,child,list,获取,跳转,Grv01,主从,view 来源: https://www.cnblogs.com/hanke123/p/15355804.html