Click here to Skip to main content
15,888,330 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
hello i have 2 forms in 1st form i have a ADD,DELETE process with a datagridview i done deleting data from database w/o updating the database but when i go to other form and back to my 1st form the data was still there i dont know how to fix it thanks

this is my code in delete button.
C#
private void btnCdelete_Click(object sender, EventArgs e)
{
      int selectedIndex = DGV_Client.CurrentCell.RowIndex;
      if (selectedIndex > 0)
      {
          DGV_Client.Rows.RemoveAt(selectedIndex);
      }
}
Posted
Updated 8-Dec-13 21:03pm
v2
Comments
s#@!k 7-Dec-13 12:19pm    
delete data form the list(what you are binding to the datagird)
Member 10189379 7-Dec-13 12:24pm    
the data must delete
s#@!k 7-Dec-13 12:28pm    
yes delete your list first if you want to update database.do compare and update in database.or make copy of your list before updating compare it.
joginder-banger 7-Dec-13 13:01pm    
some more code share for better understanding your problem
Sadique KT 9-Dec-13 6:25am    
delete it from binding source(collection/list/table etc.) .....show the code for binding...

1 solution

well you can use static datatable in c# to bind data with the datagridview. in your case you are deleteing rows only and not the data so when you come back from one page to other your grid will bind again on the page load and it will bind data from the database.


instead of doing this get static datatable will help you to maintain the values of rows during the navigation from one page to other. so when you delete a row from gridview also delete from datatable.
however be care full when you use static variable incase you have a large amount of data. it will occupy a lot of memory..
 
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