I have DataGridView
(that hold any DataBase
)
I want to insert any value into any Cell (and that this value will save on DataBase)
How to do it (in C#)
Thank's in advance
This is perfect code but it cannot add a new row:
dataGridView1.Rows[rowIndex].Cells[columnIndex].Value = value;
But this code can insert a new row:
var index = this.dataGridView1.Rows.Add();
this.dataGridView1.Rows[index].Cells[1].Value = "1";
this.dataGridView1.Rows[index].Cells[2].Value = "Baqar";
You can access any DGV cell as follows :
dataGridView1.Rows[rowIndex].Cells[columnIndex].Value = value;
But usually it's better to use databinding : you bind the DGV to a data source (DataTable
, collection...) through the DataSource
property, and only work on the data source itself. The DataGridView
will automatically reflect the changes, and changes made on the DataGridView
will be reflected on the data source
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With