博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
GridView 动态列上方添加相应的Combox等控件
阅读量:5141 次
发布时间:2019-06-13

本文共 4079 字,大约阅读时间需要 13 分钟。

Dev中的Gridview控件添加简单的动态列并不复杂,但是有时候需要在在动态列上添加对应的Combox

1  gvList.BeginUpdate(); 2 if (gcList.DataSource != null) 3 { 4    (gcList.DataSource as DataTable).Clear(); 5 } 6  gvList.Columns.Clear(); 7  8 //DataTable 形式绑定数据源 9 DataTable dt = new DataTable();10                 dt.Columns.Add("PatternPartCD", typeof(string));11                 dt.Columns.Add("PatternPartNm", typeof(string));12                 dt.Columns.Add("Size", typeof(Decimal));13                 dt.Columns.Add("TorlnceL", typeof(Decimal));14                 dt.Columns.Add("TorlnceR", typeof(Decimal));15 16                 //手动添加 Gridview列    17                 GridHelper.AddCol(gvList, _presenter._resourceService.GetResourceString("Code"), "PatternPartCD", "PatternPartCD", true, 1, 55, this._riCode);18                 GridHelper.AddCol(gvList, "* " + _presenter._resourceService.GetResourceString("PatternPartName"), "PatternPartNm", "PatternPartNm", true, 2, 180, null);19                 GridHelper.AddCol(gvList, _presenter._resourceService.GetResourceString("Standard") + _presenter._resourceService.GetResourceString("Size"), "Size", "Size", true                                     , 3, 70,  null);20                 GridHelper.AddCol(gvList, _presenter._resourceService.GetResourceString("TorlnceL"), "TorlnceL", "TorlnceL", true, 4, 70,  null);21                 GridHelper.AddCol(gvList, _presenter._resourceService.GetResourceString("TorlnceR"), "TorlnceR", "TorlnceR", true, 5, 70,  null);22 23 24 25 26                 for (i = 0; i < StyleSizeInfo.Count; i++)27                 {28                     dt.Columns.Add(StyleSizeInfo[i].SizeCD, typeof(decimal));                                           GridHelper.AddCol(gvList, StyleSizeInfo[i].SizeNm, StyleSizeInfo[i].SizeCD, StyleSizeInfo[i].SizeCD, true, j, 60, txtEdit);29                     gvList.Columns[j].DisplayFormat.FormatString = "N2";30                     gvList.Columns[j].DisplayFormat.FormatType = DevExpress.Utils.FormatType.Numeric;31                     gvList.Columns[j].Tag = "Tag";32 33                     System.Windows.Forms.ComboBox cboSize = new System.Windows.Forms.ComboBox();34 35                     cboSize.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;36                     cboSize.Enabled = true; cboSize.FormattingEnabled = true;37                     cboSize.Location = new Point(462 + i * 60, 0);//重新定位控件的位置39                     cboSize.Name = "cboBrand" + j.ToString();40                     cboSize.DataSource = dtoList;41                     cboSize.DisplayMember = "SizeNm";42                     cboSize.ValueMember = "SizeCD";  43                     this.panelbtn2.Controls.Add(cboSize);44 45                 dt.Columns.Add("PlusTol", typeof(Decimal));46                 dt.Columns.Add("MinusTol", typeof(Decimal));47                 dt.Columns.Add("Measurement", typeof(string));48 49                 GridHelper.AddCol(gvList, _presenter._resourceService.GetResourceString("PlusTol"), "PlusTol", "PlusTol", true, j, 70, null);50                 GridHelper.AddCol(gvList, _presenter._resourceService.GetResourceString("MinusTol"), "MinusTol", "MinusTol", true, j + 1, 70, null);51                 GridHelper.AddCol(gvList, "* " + _presenter._resourceService.GetResourceString("PatternSizeChkMethod"), "Measurement", "Measurement", true, j + 2, 550, null);

注意:

1.最好将添加的控件单独放到一个panel上,方便重新定位或者遍历所有的新添加的控件:

foreach (Control item in panel1.Controls)// {   if (item is System.Windows.Forms.ComboBox)   {    (item as System.Windows.Forms.ComboBox).Name = "新名字";   } }

2.如果绑定的是有数据源的控价且控价数据源相同时,需要重新Copy数据源,否则可能会导致添加的控件变得一致:

1     public class Employee : ICloneable//添加Copy方法到类内 2     { 3         public string name { get; set; } 4         public object Clone() 5         { 6             return this.MemberwiseClone(); 7         } 8     } 9 10 List
EmployeeList = new List
11 12 foreach (Employee dto in EmployeeList )13 {14 dtoList.Add(dto.Clone() as IF_StyleSizeInfo);15 }
Clone 类

 

转载于:https://www.cnblogs.com/zyblogs/p/4135131.html

你可能感兴趣的文章
java代码编译与C/C++代码编译的区别
查看>>
Bitmap 算法
查看>>
转载 C#文件中GetCommandLineArgs()
查看>>
list control控件的一些操作
查看>>
绝望的第四周作业
查看>>
一月流水账
查看>>
npm 常用指令
查看>>
判断字符串在字符串中
查看>>
Linux环境下Redis安装和常见问题的解决
查看>>
HashPump用法
查看>>
cuda基础
查看>>
Vue安装准备工作
查看>>
oracle 创建暂时表
查看>>
201421410014蒋佳奇
查看>>
Xcode5和ObjC新特性
查看>>
LibSVM for Python 使用
查看>>
Centos 7.0 安装Mono 3.4 和 Jexus 5.6
查看>>
CSS属性值currentColor
查看>>
java可重入锁reentrantlock
查看>>
浅谈卷积神经网络及matlab实现
查看>>