Click here to Skip to main content
14,693,622 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
How do I change the value of a selected cell using a button for e.g. changing a cell value from 1 to 2

What I have tried:

int row = 0;
row = dataGridView1.Rows.Count - 2;
dataGridView1["Amount", row].Value = Keytxt.Text;
This is my current solution but it only changes the value of the last cell in the column.
Updated 10-Aug-20 1:42am
BillWoodruff 8-Aug-20 5:39am
Note: the OP received a usable answer to the same question on SO an hour ago.

1 solution

You need to use the Selected cell, instead of the last-but-one.
See here: Get the Selected Cells, Rows, and Columns in DataGridView Control - Windows Forms | Microsoft Docs[^]
BillWoodruff 8-Aug-20 2:03am
Comment moved to OP. I assure you there was no criticism implied !

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900