user3377879
user3377879

Reputation: 43

How to get values from data grid view in c#?

I tried with this code..

for (int i = 0; i < datagridItemEntry.RowCount; i++)
{
     int a = Convert.ToInt32(datagridItemEntry.Rows[i].Cells[4].Value);
     int b = Convert.ToInt32(datagridItemEntry.Rows[i].Cells[5].Value);
     int c = a * b;
     datagridItemEntry.SelectedRows[i].Cells[6].Value = c.ToString();
}

I want value of cell 4 & 5 to be get multiplied and the result should be reflect in cell 6.. Nothing is happening with the above code.. Help me with the proper code..

Upvotes: 1

Views: 998

Answers (1)

user3391751
user3391751

Reputation:

Your problem may be here

 datagridItemEntry.SelectedRows[i].Cells[6].Value = c.ToString();

Replace .SelectedRows to .Rows

for (int i = 0; i < datagridItemEntry.RowCount; i++)
{
     int a = Convert.ToInt32(datagridItemEntry.Rows[i].Cells[4].Value);
     int b = Convert.ToInt32(datagridItemEntry.Rows[i].Cells[5].Value);
     int c = a * b;
     datagridItemEntry.Rows[i].Cells[6].Value = c.ToString();
}

Upvotes: 2

Related Questions