使用拖放进行网格视图行排序

本文关键字:网格 排序 视图 拖放 | 更新日期: 2023-09-27 18:27:18

如何通过拖放来更改RadGridview(Telerik组件)的行。

我想要物品。插入(i,commonhaber)而非项目。添加但我不知道删除索引(i)。

void gridView_News_Drop(object sender, DragEventArgs e)
{
            var DroppedControl = e.Data.GetData("interpressentitygridview") as RadGridView;
            if (DroppedControl==null)
            return;
            IList<CommonHaber> tempHabers=new List<CommonHaber>();
                foreach (CommonHaber commonHaber in DroppedControl.SelectedItems)
                {
                    tempHabers.Add(commonHaber);
                    gridView_gruphaber.Items.Add(commonHaber);
                }
}

使用拖放进行网格视图行排序

我解决了如何查找索引的问题。给你

 gridView_gruphaber.RowLoaded += new EventHandler<RowLoadedEventArgs>(gridView_News_RowLoaded);
void gridView_News_RowLoaded(object sender, RowLoadedEventArgs e)
    {
        GridViewRow row = e.Row as GridViewRow;
        if (row != null)
        {
            row.PreviewDrop += new DragEventHandler(row_PreviewDrop); 
        }
    }
    private int droppedRowIndex = -1;
    void row_PreviewDrop(object sender, DragEventArgs e)
    {
        GridViewRow row = sender as GridViewRow;
        if (row != null)
        {
            CommonHaber droppedCommonHaber = row.Item as CommonHaber;
            droppedRowIndex = gridView_gruphaber.Items.IndexOf(droppedCommonHaber);
        }
    }