Set DataGridView cell value and add a new row
-
I have an unbound DataGridView control with two columns. The first one is a DataGridViewButtonColumn and the second DataGridViewTextBoxColumn. When my form is first shown the DGW is empty and the only row is the one with the * in the row header (new/empty row) When I click a cell in the first column an OpenFileDialog gets shown and when I select a file the file name is written in the second cell in the same row. This works, but the row is still marked with * and a new row isn't added. If I edit the second cell manually, the row header is marked with the pencil sign and a new/empty row is added below. Is there a way to achieve this when I edit a cell programatically? Here is my current code:
private void dataGridView1\_CellContentClick( object sender, DataGridViewCellEventArgs e) { if (e.ColumnIndex == 0) { SelectFile(e.RowIndex); } } private void SelectFile(int rowIndex) { if (openFileDialog.ShowDialog() == DialogResult.OK) { dataGridView1.Rows\[rowIndex\].Cells\[1\].Value = openFileDialog.FileName; dataGridView1.CurrentCell = dataGridView1.Rows\[rowIndex\].Cells\[1\]; } }
The bearing of a child takes nine months, no matter how many women are assigned.