Hello Mat

 找回密码
 立即注册
查看: 7174|回复: 7

DataGridView写入

[复制链接]

84

主题

115

帖子

731

金钱

管理员

Rank: 9Rank: 9Rank: 9

积分
1467
发表于 2020-1-1 23:46:37 | 显示全部楼层 |阅读模式


  1.                 DrawDataRows = 0;    // 行数
  2.                 DrawData = new DataTable();
  3.                 // 表头
  4.                 DrawData.Columns.Add("Class", typeof(String));
  5.                 DrawData.Columns.Add("Row", typeof(String));
  6.                 DrawData.Columns.Add("Col", typeof(String));
  7.                 DrawData.Columns.Add("Lenth", typeof(String));
  8.                 DrawData.Columns.Add("Width", typeof(String));
  9.                 // 每一行的内容
  10.                 DataRow DrawDataRow = DrawData.NewRow();
  11.                 DrawDataRow[0] = "y123";
  12.                 DrawDataRow[1] = "s1";
  13.                 DrawDataRow[2] = "d0";
  14.                 DrawDataRow[3] = "d0";
  15.                 DrawDataRow[4] = "f0";
  16.                 DrawData.Rows.Add(DrawDataRow);
  17.                 // 显示DataGrid
  18.                 this.dataGridView1.DataSource = null;
  19.                 this.dataGridView1.DataSource = DrawData;
  20.                 //不显示出dataGridView1的最后一行空白
  21.                 this.dataGridView1.AllowUserToAddRows = false;
复制代码


回复

使用道具 举报

1294

主题

1520

帖子

110

金钱

管理员

Rank: 9Rank: 9Rank: 9

积分
22633
发表于 2020-1-12 14:30:22 | 显示全部楼层
  1.             int index = this.dataGridView1.CurrentRow.Index;    //取得选中行的索引  
  2.             string row_pos = this.dataGridView1.Rows[index].Cells["Row"].Value.ToString();   //获取单元格列名为‘Row’的值
复制代码


选择某一行的数据;
算法QQ  3283892722
群智能算法链接http://halcom.cn/forum.php?mod=forumdisplay&fid=73
回复 支持 反对

使用道具 举报

1294

主题

1520

帖子

110

金钱

管理员

Rank: 9Rank: 9Rank: 9

积分
22633
发表于 2020-1-12 15:15:13 | 显示全部楼层
  1.                         if (this.dataGridView1.RowCount > 0)
  2.                         {
  3.                             int lastRow = this.dataGridView1.RowCount;
  4.                             DataGridViewRow currentRow = this.dataGridView1.Rows[lastRow - 1];
  5.                             this.dataGridView1.Rows.Remove(currentRow);//删除行
  6.                         }
复制代码
算法QQ  3283892722
群智能算法链接http://halcom.cn/forum.php?mod=forumdisplay&fid=73
回复 支持 反对

使用道具 举报

1294

主题

1520

帖子

110

金钱

管理员

Rank: 9Rank: 9Rank: 9

积分
22633
发表于 2020-1-12 15:27:23 | 显示全部楼层
  1.         private void dataGridView1_CellMouseUp(object sender, DataGridViewCellMouseEventArgs e)
  2.         {
  3.             // 删除右键删除
  4.             if (e.Button == MouseButtons.Right)//判断是否当前弹起的右键
  5.             {
  6.                 try
  7.                 {
  8.                     this.dataGridView1.Rows[e.RowIndex].Selected = true;//选中鼠标所在的当前行
  9.                     DataGridViewRow currentRow = this.dataGridView1.Rows[e.RowIndex];
  10.                     this.dataGridView1.Rows.RemoveAt(e.RowIndex);
  11.                 }
  12.                 catch { }
  13.             }

  14.         }
复制代码
删除鼠标右键指定的一行;
算法QQ  3283892722
群智能算法链接http://halcom.cn/forum.php?mod=forumdisplay&fid=73
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

Python|Opencv|MATLAB|Halcom.cn ( 蜀ICP备16027072号 )

GMT+8, 2024-4-20 04:55 , Processed in 0.250651 second(s), 24 queries .

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表