如何在Winforms的Infragistics UltraGrid控件中按索引删除行?

时间:2011-07-29 13:07:15

标签: c# winforms infragistics ultragrid

我有一个Windows窗体,里面有一个UltraGrid组件。

我想通过使用它的数字索引删除一行,我该如何实现? Infragistics的文档非常缺乏,我似乎无法找到相关信息。

有什么建议吗?

2 个答案:

答案 0 :(得分:2)

我建议从列表中删除WinGrid绑定的项目,这将从网格中删除它。如果您知道列表中项目的索引,则可以使用RemoveAt方法将其从列表中删除。

如果您对要删除的UltraGridRow对象有引用,则可以使用将UltraGridRow的ListObject属性传递的Remove方法传递给列表的Remove方法。

艾伦

答案 1 :(得分:1)

我找到了这个示例代码;

protected void wgSubstancesUsed_UpdateRow(object sender, Infragistics.WebUI.UltraWebGrid.RowEventArgs e)
{
    switch (e.Row.DataChanged)
    {
        case Infragistics.WebUI.UltraWebGrid.DataChanged.Added:
            this.InsertRecord(e.Row);
            break;

        case Infragistics.WebUI.UltraWebGrid.DataChanged.Modified:
            this.UpdateRecord(e.Row);
            break;

        case Infragistics.WebUI.UltraWebGrid.DataChanged.Deleted:
            this.DeleteRecord(e.Row);
            break;

    }

}

private void DeleteRecord(UltraGridRow theGridRow)
{
    //Get the GUID of the record you wish to delete from the grid (for me
    //  the first hidden field of the grid
    Guid thePrimaryKey = new Guid(theGridRow.Cells[0].Value.ToString());
    if (thePrimaryKey != null)
    {
        busClientObject oClient = new busClientObject()
 oClient.Load(thePrimaryKey);  //Get to the individual record, load it into the object
        oClient.DataRow.Delete();  //Mark that record for deletion
        oClient.Save();    //Actually delete it
    }

}

另外看看这些文章

http://devcenter.infragistics.com/Support/KnowledgeBaseArticle.aspx?ArticleID=7384

http://forums.infragistics.com/forums/p/24697/90536.aspx

http://devcenter.infragistics.com/Support/KnowledgeBaseArticle.aspx?ArticleID=7384