Click here to Skip to main content
15,884,388 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I have two datagridview controls on a form.When we the selection changes in DGV1 the DGV2 rows gets filtered depending on ID in DGV1.Now if I make a change in the cell of DGV2 a columns called Amount gets updated in DGV1. I have achieved this using cell value changed and its working fine.For this I am using a datatable.So when i want to save changes in the dgv2 in the database.The value entered in DGV2 is not saved.For that I am also changing the value in datable depending on the row index.Below is the data in DGV1

ID Qty UnitPrice Amount
-----------------------

1 - 20 - 2 - 40
2 - 40 - 3 - 120



in DGV2 below is the data

ID SellQty
-----------
1 - 5
2 - 10
1 - 15
2 - 10


So when user click on any cell in DGV1 the DGV2 rows get filtered(as you can see in DGV1 for ID=1 there are 2 values).All this is fine. Below is the line of code i have written in Cellvalue changed of DGV2 so that the datatable cells are also updated as I need to save in the database using foreach loop.

dtBatch.Rows[i].SetField(SellQty, gvBatchDetails.Rows[i].Cells[SellQty].Value);



I am using a variable i (int).But when the row is filtered when the user enters ID 2 in DGV1 the i value also changes to 0 for first row.Where as in Datatable ID 2 is at index 1.So how to make changes in the datatable in this case.Even if i Replace i with e.RowIndex still the same rows in datatable gets updated as I am filtering the data on CellEnter.
Posted

1 solution

SQL
I have solved the issue by getting the selected row from datagridview.

    DataRow[] rowList = QuoteSalesItemSearch.dtBatch.Select("BatchItemID='" + ItemID + "'" + "and BatchNo='" + BatchNo + "'");
  foreach (DataRow dr in rowList)
   dr["SellQty"] = gvBatchDetails.Rows[e.RowIndex].Cells["SellQty"].Value;
 
Share this answer
 

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