C#dataGridView 批量修改数据

Form1.cs
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; namespace WindowsFormsApplication1 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void Add_Button_Click_1(object sender, EventArgs e) { int index = this.dataGridView1.Rows.Add(); this.dataGridView1.Rows[index].Cells[0].Value = index; this.dataGridView1.Rows[index].Cells[1].Value = "ababc"; this.dataGridView1.Rows[index].Cells[2].Value = "ABCBC"; } private void Query_Button_Click_1(object sender, EventArgs e) { Console.WriteLine("Query"); Console.WriteLine("取得当前单元格内容" + dataGridView1.CurrentCell.Value); Console.WriteLine("取得当前单元格的列数" + dataGridView1.CurrentCell.ColumnIndex); Console.WriteLine("取得当前单元格的行数" + dataGridView1.CurrentCell.RowIndex); } private void AddM_Button_Click_1(object sender, EventArgs e) { DataGridViewRow row = new DataGridViewRow(); DataGridViewTextBoxCell textboxcell = new DataGridViewTextBoxCell(); textboxcell.Value = "aaa"; row.Cells.Add(textboxcell); DataGridViewComboBoxCell comboxcell = new DataGridViewComboBoxCell(); string[] jgStr = new string[] { "砖混", "框混", "全框架", "其它" }; comboxcell.DataSource = jgStr; comboxcell.Value = "框混"; row.Cells.Add(comboxcell); dataGridView1.Rows.Add(row); // 固定第一行 dataGridView1.Rows[0].Frozen = true; } private void button1_Click_1(object sender, EventArgs e) { int c = dataGridView1.SelectedCells.Count; for (int i = 0; i < c; i++) { dataGridView1.SelectedCells[i].Value = textBox1.Text; } } } }

浙公网安备 33010602011771号