George William

George William

  • 2k
  • 10
  • 292

Editing a cell in a selected datagrid view.

Jan 30 2021 11:46 AM
I am trying to develope an application that opens csv file with 4 colums. Having 3 colums read only, I want to edit the csv file's fouth column after save the file.
 
However in my code, the row is selected, and cell data all listed in text boxes where the 3 colums of data are read only. however on editing the text of the 4th column, its only the cell of the first colum that changes.
 
Below is part of the code that handles the editing.
 
private void Update_Btn_Click(object sender, EventArgs e)
        {
            System.Text.StringBuilder sb = new System.Text.StringBuilder();
            int x = 3;
            DataTable dt = new DataTable();
            DataGridViewRow newDataRow = dataGridView1.Rows[selectedRow];
            //newDataRow.Cells[x].Value = textBoxOrd.Text;
            
            for (int i = 0; i <= 3; i++)
            {
                //sb.Append("Row: ");
                newDataRow.Cells[i].Value = textBoxOrd.Text;
                sb.Append(dataGridView1.SelectedCells[i].RowIndex.ToString());
                sb.Append(", Column: ");
                sb.Append(newDataRow.Cells[i].Value.ToString());
                //sb.Append(dataGridView1.SelectedCells[i].ColumnIndex.ToString());
                //sb.Append(Environment.NewLine);

            }
        }
 

Attachment: Woodstock.zip

Answers (10)