C#的datagridview使用总结
1.编辑行中内容
this.dataGridView1.Rows[GlobleVariable.VarNum].Cells[1].Value = value1;
2.删除指定行
dataGridView1.Rows.Remove(dataGridView1.SelectedRows[0]);
3.设置成选中整行:选择模式设置成FullRowSelect
4.查找指定内容
for (int i = 0; i < dataGridView1.Rows.Count; i++){for (int j = 0; j < dataGridView1.Columns.Count; j++){var Value = Convert.ToString(dataGridView1.Rows[i].Cells[j].Value);if (Value == "Temp01"){dataGridView1.Rows[i].Cells[j].Selected = true; //找到后单元zhi格被dao选中}}}
5.取消当前的选择
dataGridView1.ClearSelection();//取消当前的选择
6.修改内容
var Gather = dataGridView1.SelectedCells;for (int i=1; i< Gather.Count; i++){Gather[i].Value = str[i];}
7.选中单行,禁止多选
属性MultiSelect=false