POV
POV

Reputation: 12015

How to get cell name in this case?

In standard method DataBindingComplete I iterate rows/cols like as:

for (int row = 0; row < dataGridView1.Rows.Count; row++)
{
    for (int column = 0; column < dataGridView1.Columns.Count; column++)
    {
        object value = dataGridView1[column, row].Value;
        if (value != null && value.GetType() == typeof(string))
        {
            (...)
        }
    }
}

How to check cell name like as?

I tried to do this:

if (dataGridView1[column, row].Name == "name") 
{
}

Edit 1 When I use CellFormatting then all cells start jumping after horizontal scrolling. Seems something wrong with rendering. Look at pic.

enter image description here

Upvotes: 0

Views: 629

Answers (1)

Dimos K
Dimos K

Reputation: 152

Wire CellFormatting event and try following code for changing the value of the cell.

private void dataGridView1_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)
{
    if (this.dataGridView1.Columns[e.ColumnIndex].Name == "dataGridViewTextBoxColumn45")
        e.Value = "oleg";
}

Upvotes: 1

Related Questions