Dear All,
Please need your support i am trying to update datagriviwe from another form textbox but cannot please need your support.
Below for you refrence.

C#
private void btntupdate_modify_Click(object sender, EventArgs e)
{
try
{
POS form1 = new POS();
DataGridView Main_dg = (DataGridView)form1.Controls["dataGridView1"];
for (int i = 0; i < Main_dg.Rows.Count; i++)
{
Main_dg.Rows[i].Cells[2].Value = txtupdate_grampcs.Text;
Main_dg.Rows[i].Cells[3].Value = txtupdate_unitprice.Text;
Main_dg.Rows[i].Cells[4].Value = txtupdate_total.Text;
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
Sachin SinghRank #66 · 26.2K reputationPosted Feb 2, 2023, 10:14 AM EST
create a class file in your project as
public class Class1 { static string _grampcs, _unitprice,_total; public static string grampcs{ get { return _grampcs; } set { _grampcs= value; } } public static string unitprice{ get { return _unitprice; } set { _unitprice= value; } } public static string total{ get { return _total; } set { _total= value; } } }In Form 2 (where you have textboxes) set the above fields as
Class1.total=txtTotal.Text; //so on for other fieldsin First form (Where you have DataGridView)
Main_dg.Rows[i].Cells[2].Value = Class1.txtupdate_grampcs; Main_dg.Rows[i].Cells[3].Value = Class1.unitprice; Main_dg.Rows[i].Cells[4].Value = Class1.total;Feroz KhanRank #3,748 · 395 reputationPosted Feb 5, 2023, 6:54 AM EST
Dear Sachin,
Thank you for your reply.
But issue you can see below snap when i double click the griview row data is coming from same row in another form textbox but when i am updating showing error like below.
Error