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

I need the way forward on this problem , any assistance will help. I have a project am working on and within the project i defined a data table (H_dt) with columns which loads data on a datagridview (DGViewitems) control row after row.

i thought of a scenario where the user might want to delete the last row or delete all the row from bottoms up ( bottom to top). so i tried this code under the "delete" button click event:

H_dt.rows(H_dt.rows.count-1).delete

but i noticed that when run this command i don't notice any change(physical change in removal of the last row) on the datagrid view, but when i add an item to the to the datagrid view via the data table the item i deleted is removed before the new item or row is added, this implies that the code in the delete button click event actually deleted the last row but the changes to the datagrid view were not just physically effected immediately, so how can i achieve this so that when the user deletes the last row he or she can see it effected right away. before they start adding new items or rows.

i also have the same problem for this line of command which is under the "clear all" button click event which clears all chosen or selected orders or existing rows.

H_dt.row.clear

all the items are actually cleared but the change doesn't seem to be effected physically on the control.

but when you start adding new items , the grid will be cleared and your new selections will be added row by row.

also i tried running this command under the "delete" button click event

DGViewitems.rows.clear (i.e running the code directly on the datagrid control)

but i get an error message "Cannot clear this list"


please note that the data table is not bound to any database table or dataset.

regards

ade
Posted

Reassign the datatable to datasource in your "Clear All" & "Delete" events.

DGViewitems.DataSource = H_dt;
 
Share this answer
 
v2
Comments
mabadeje 3-Jul-13 13:04pm    
thanks so much , now working fine
ArunRajendra 3-Jul-13 23:10pm    
Welcome :)
mabadeje 4-Jul-13 8:37am    
hi arunrajendra,
But this doesn't seem to be working for a situation where you wish to clear all see code below to clear the data grid of all rows:

DGViewitems.datasource = H_dt
DGViewitems.rows.clear

it comes back with this error "Cannot clear this list"

what do you think

regards

ade
ArunRajendra 4-Jul-13 8:56am    
Instead of clearing the Data brid clear the table and assign it back to datasource.
Just bind your datagridview again with datatable once you deleted item from datatable.Since grid is used just to display the content,if you wont rebind it,it would display old records only.

Regards..:laugh:
 
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