开发者经常会利用datagridview做添加,修改,删除操作,有时还要同步更新到数据库,有时需要修改整行,有时需要修改整列,有时修改多行,多列。
现在先写个修改某一列的选中行的内容,借此抛砖引玉
int Count=this.DataGridView1.SelectedCells.Count;
DateTime dtStartTime123 = Convert.ToDateTime(this.dataGridView1.SelectedCells[0].OwningRow.Cells[1].Value.ToString());
startTime123 = dtStartTime123.ToString("yyyyMMddHHmm");
DateTime dtEndTime123 = Convert.ToDateTime(this.dataGridView1.SelectedCells[this.dataGridView1.SelectedCells.Count - 1].OwningRow.Cells[1].Value.ToString());
endTime123 = dtEndTime123.ToString("yyyyMMddHHmm");
columnName = this.dataGridView1.SelectedCells[0].OwningColumn.DataPropertyName.ToString();