Home > Mobile >  Write to multiple Cells of a DataGridView in the same column at the same time
Write to multiple Cells of a DataGridView in the same column at the same time

Time:09-21

Is there any way to write on all cells at the same time when introducing data on the first cell of one column?
For example if I put 1 in the Data Column, auto-fill every cell on this Column.

An example in these images:

Image11 Image22

I have tried working with events:

private void dataGridView1_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e)
 {
     // [...}
    else if (titletext2.Equals("Data"))
    {
        foreach (DataRow row in dataGridView1.Rows)
        {
            
        }
    } 
}

CodePudding user response:

Please refer to the following codes

    private void dataGridView1_CellValueChanged(object sender, DataGridViewCellEventArgs e)
    {
        if (dataGridView1.Columns[e.ColumnIndex].Name.Equals("Data") && e.RowIndex == 0)
        {
            string newValue = dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex].Value.ToString();

            for (int i = 0; i < dataGridView1.RowCount; i  )
            {
                dataGridView1.Rows[i].Cells[e.ColumnIndex].Value = newValue;
            }
        }
    }
  • Related