清除数据表 [英] clearing the data table

查看:113
本文介绍了清除数据表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,



我需要解决这个问题的方法,任何帮助都会有所帮助。我有一个正在进行的项目,在项目中我定义了一个数据表(H_dt),其中的列在datagridview(DGViewitems)控件的行上加载数据。



i想到了一个场景,用户可能想要删除最后一行或从底部向上删除所有行(从下到上)。所以我在删除按钮点击事件下尝试了这个代码:



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



但我注意到在运行此命令时我没有注意到数据网格视图上的任何更改(删除最后一行的物理更改),但是当我向项目添加项目时datagrid视图通过数据表删除的项目在添加新项目或行之前被删除,这意味着删除按钮单击事件中的代码实际上删除了最后一行,但对数据网格视图的更改不仅仅是物理上立即生效,我怎么能实现这一点,以便当用户删除最后一行时,他或她可以立即看到它。在他们开始添加新项目或行之前。



i对于这一命令行也存在同样的问题,这是在全部清除按钮点击事件下清除所有选择的或者选择的订单或现有的行。



H_dt.row.clear



所有物品实际上已被清除但是这个改变似乎并没有在控制器上实际受到影响。



但是当你开始添加新项目时,网格将被清除,你的新选择将是逐行添加。



我也尝试在删除按钮点击事件下运行此命令



DGViewitems.rows.clear(即直接在datagrid控件上运行代码)



但我收到错误消息无法清除此列表





请注意,数据表未绑定到任何数据库表或数据集。



问候



ade

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

推荐答案

在全部清除和删除事件中将数据表重新分配给数据源。



DGViewitems.DataSource = H_dt;
Reassign the datatable to datasource in your "Clear All" & "Delete" events.

DGViewitems.DataSource = H_dt;


从datatable中删除项目后,再次使用datatable再次绑定datagridview。由于网格仅用于显示内容,如果不重新绑定,它将仅显示旧记录。



问候......:笑:
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:


这篇关于清除数据表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆