简体   繁体   English

如何从 C# 中的 DataGrid 中删除一行?

[英]How do you delete a row from a DataGrid in C#?

I have an app for a Windows CE 6.5 mobile device.我有一个适用于 Windows CE 6.5 移动设备的应用程序。 I am using Visual Studio 2008, coding in C# Windows Forms in a Smart Device Project.我正在使用 Visual Studio 2008,在智能设备项目中的 C# Windows 窗体中编码。 I have used a datagrid (not datagridview as these are not available).我使用了一个数据网格(不是 datagridview,因为它们不可用)。 I am trying to delete the selected row but I cannot figure it out.我正在尝试删除选定的行,但我无法弄清楚。

I have researched it but everything comes back with deleting from datagridview where you can use .selectedrow .我已经研究过它,但一切都会从 datagridview 中删除,您可以在其中使用 .selectedrow 。 Can anyone point me in the right driection as to how to do this?任何人都可以指出我如何做到这一点的正确方向吗?

Attached is a photo to show that selectedrow isnt an option附上一张照片,表明 selectedrow 不是一个选项

选项

You can use CurrencyManager class for this purpose like this:为此,您可以使用CurrencyManager类,如下所示:

var manager = (CurrencyManager)this.BindingContext[dataGrid1.DataSource];
var currentIndex = manager.Position;
manager.RemoveAt(currentIndex);
manager.Refresh();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM