Gridview行使用DragDrop进行排序

时间:2014-10-20 08:52:34

标签: c# sorting drag-and-drop radgridview

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

我想要items.Insert(i,commonhaber)而不是items.Add但我不知道drop index(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);

                }
}

1 个答案:

答案 0 :(得分:0)

我解决了如何找到索引。你在这里......

 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);

        }
    }