当前位置: 首页 > news >正文

建设网站深圳市建导航网站

建设网站深圳市,建导航网站,能看的网站给我一个呗,厦门网站建设策划转载#xff1a; http://blog.163.com/zjlovety126/blog/static/2241862420106128264300/ 也不知道是否该应用这个控件#xff0c;不过也想不出该用其他什么控件#xff0c;关键是俺比较菜没什么经验。 要求是这样的#xff0c;用户一次添加一个任务#xff0c;这个任务有…转载 http://blog.163.com/zjlovety126/blog/static/2241862420106128264300/ 也不知道是否该应用这个控件不过也想不出该用其他什么控件关键是俺比较菜没什么经验。 要求是这样的用户一次添加一个任务这个任务有三个选项其中两个选项是用户动态输入的名称就象图中bb和dd两列另一个选项则是一堆数据就象qq那列我现在要把每个任务罗列出来不能用treeview不能用tabcontrol不能用xml最好象个表格一样清晰明朗疯了每个任务对应两个按钮一个是Run为了跑任务一个是Remove为了移除任务。     当然最开始选择DataGridView就是为了满足那个“象表格一样清晰明朗”的奇怪需求一行对应一个任务其次貌似DataGridView控件在.net 2.0中加入了新的特征如DataGridViewButtonColumn啊DataGridViewComboBoxColumn之类的东东。研究了一天才发现这两个东东根本派不上用场首先DataGridViewButtonColumn中的Button跟真的Button根本没得比既不能添加Button的Text也不好添加Click事件应该是有方法的但还是很别扭而且也没研究其次是DataGridViewComboBoxColumn不仅外观上不能和真正的ComboBox相提并论而且当你选择了其中的任一itemDataGridView就会新增一行这跟我们的需求是完全不符合的毕竟一个选项是不能代表一个任务的。 从网上查了很多资料呵呵看到一篇说可以画个控件上去觉得很有意思。其实我就是这么做的。 1首先初始化DataGridView控件。 private void Form1_Load(object sender, EventArgs e) { DataGridViewCellStyle columnHeaderStyle  new DataGridViewCellStyle();             columnHeaderStyle.BackColor  Color.Beige;             columnHeaderStyle.Font  new Font(Verdana, 10, FontStyle.Bold);             dataGridView1.ColumnHeadersDefaultCellStyle columnHeaderStyle;             this.dataGridView1.Columns.Add(1, bb);             this.dataGridView1.Columns.Add(2, qq);             this.dataGridView1.Columns.Add(3, dd);             this.dataGridView1.Columns.Add(4, aa); } 2单击按钮添加一行包括单元格和单元格的值看似内嵌在单元格中的按钮和下拉列表 private void button4_Click(object sender, EventArgs e) {             DataGridViewRow dr  new DataGridViewRow();             foreach (DataGridViewColumn c in this.dataGridView1.Columns)             {                 dr.Cells.Add(c.CellTemplate.Clone() as DataGridViewCell);  //给行添加单元格             } dr.Cells[0].Value  1111;             dr.Cells[2].Value  3333;             this.dataGridView1.Rows.Add(dr);             int index  this.dataGridView1.Rows.Count - 2;               ComboBox com  new ComboBox();             com.Name  Containers  index.ToString(); ;             com.DropDownStyle System.Windows.Forms.ComboBoxStyle.DropDownList;             com.FlatStyle System.Windows.Forms.FlatStyle.Flat;             com.Items.AddRange(new object[] {             1,             2,             3,             4});             com.SelectedIndex 0;             this.dataGridView1.Controls.Add(com);             this.dataGridView1.Columns[1].Width com.Width;             com.Location  newSystem.Drawing.Point(((this.dataGridView1.GetCellDisplayRectangle(1, index,true).Right) - (com.Width)), this.dataGridView1.GetCellDisplayRectangle(1, index,true).Y);               Button btn1  new Button();             btn1.Name  btnRun  index.ToString(); ;             btn1.Text  Run;             btn1.Clicknew EventHandler(btn1_Click);               Button btn2  new Button();             btn2.Name  btnRemoveindex.ToString();             btn2.Text  Remove;             btn2.Clicknew EventHandler(btn2_Click);               this.dataGridView1.Controls.Add(btn1);             this.dataGridView1.Controls.Add(btn2);             this.dataGridView1.Columns[3].Width btn1.Width btn2.Width 6;             btn1.Location  newSystem.Drawing.Point(((this.dataGridView1.GetCellDisplayRectangle(3, index,true).Left)), this.dataGridView1.GetCellDisplayRectangle(3, index, true).Y);             btn2.Location  new System.Drawing.Point(((this.dataGridView1.GetCellDisplayRectangle(3, index,true).Right-1) - (btn2.Width)), this.dataGridView1.GetCellDisplayRectangle(3, index,true).Y);         } 3为2中生成的Run按钮和Remove按钮添加单击事件处理程序 public void btn1_Click(object sender, EventArgs e) {             this.richTextBox1.Text  ;             Button btn (Button)(sender);             //这个btn的name是btnRun打头的             string suffix btn.Name.ToString().Substring(6); //后边那个号相当于index的string             Control c findControlByName(suffix);               if (c ! null)             {                 ComboBox com (ComboBox)(c);          //Control ctl1 this.dataGridView1.Controls[Containers i.ToString()];         //ComboBox com (ComboBox)ctl1;  其实这样写更简单点                 for (int i 0; i com.Items.Count; i)                 {                     this.richTextBox1.Text com.Items[i].ToString()  \n;                 }             } }   public void btn2_Click(object sender, EventArgs e)  {         int RowCount  this.dataGridView1.Rows.Count;       Button btn (Button)(sender);             //这个btn的name是btnRemove打头的             string suffix btn.Name.ToString().Substring(9);  //后边那个号相当于index的string             this.dataGridView1.Controls.RemoveByKey(btn.Name);             this.dataGridView1.Controls.RemoveByKey(btnRun  suffix);             this.dataGridView1.Controls.RemoveByKey(Containers  suffix);             int index  Convert.ToInt32(suffix);             this.dataGridView1.Rows.RemoveAt(index);        if (index RowCount - 2)             {                 for (int i index 1; i RowCount - 1; i)                  {                     Control ctl1  this.dataGridView1.Controls[Containers  i.ToString()];                     Control ctl2  this.dataGridView1.Controls[btnRun  i.ToString()];                     Control ctl3  this.dataGridView1.Controls[btnRemove  i.ToString()];                     ComboBox com (ComboBox)ctl1;                     Button btnRun (Button)ctl2;                     Button btnRemove (Button)ctl3;                     //上移一格单元格Height位4Button的Height为23                     com.Location  new System.Drawing.Point(com.Location.X, com.Location.Y - 23);                     btnRun.Location  new System.Drawing.Point(btnRun.Location.X, btnRun.Location.Y - 23);                     btnRemove.Location  new System.Drawing.Point(btnRemove.Location.X, btnRemove.Location.Y - 23);                     //改名字的后缀                     int ji-1;                     com.Name  Containers  j.ToString();                     btnRun.Name  btnRun  j.ToString();                     btnRemove.Name  btnRemove  j.ToString();                 }             } } 4btn1_Click处理中用到的函数findControlByName() public Control findControlByName(string suffix) {             foreach (System.Windows.Forms.Control c in this.dataGridView1.Controls)             {                 if (c.Name  Containers  suffix)                     return c;             }             return null; } 写的比较累赘不知道还有什么更好的方法。请经验人士赐教^_^     转载于:https://www.cnblogs.com/timeover/archive/2010/09/15/1826900.html
http://www.yutouwan.com/news/312235/

相关文章:

  • 健康管理公司网站建设网站建设与网页设计课
  • 买空间送网站怎么创建一个博客网站
  • 客户对网站建设公司的评价网页设计模板图片
  • 网站站内推广计划书上海家装口碑最好的公司
  • 甘肃建设厅网站首页哪里有免费的ppt模板下载网站
  • 公司建站后还要录入网页吗网站推广在哪好外贸
  • 农产品网站设计巴州建设工程信息网
  • 中小企业网站建设如何网站用什么技术做的
  • 网站模板 缓存商标免费下载模板ppt
  • 东莞网站定制网页游戏修改器
  • 上海模板建站源码查国外网站备案
  • 广州专业网站改版领军企业加快wordpress图片的插件
  • 做网站开发的公司销售阿盟住房与建设局门户网站
  • 山东丽天建设集团网站济南商城网站建设
  • 景德镇网站维护公司广告片拍摄公司
  • 医保局网站建设网站开发实训意义
  • 做淘宝客网站流量选择网站建设的步骤图片过程
  • oa连接到网站的链接怎么做游戏网站模板源码
  • 广州企业网站定制微信公众号怎么上架商品
  • 建网站备案需要的材料以星空做的网站模板
  • wordpress客户端插件下载优化网站关键词
  • 做婚宴的网站有哪些人力资源网站建设方案
  • 购物网站制作例子快递物流公司网站模板
  • 营销型网站的建设重点是什么商城网站代理系统
  • 正规的食品行业网站开发湖北专业网站建设耗材
  • php可以做视频网站吗网站流量统计怎么做的
  • 社区推广宣传活动方案网站推广优化外包便宜
  • 能利用双股铜芯电话线做网站吗wordpress pdf 免费下载
  • 721网站建设四川省的建设厅注册中心网站首页
  • 泰州网页网站制作网站推广策划方案大数据精准获客