简体   繁体   中英

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..

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();
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM