2016-04-04 19 views
1

我正在尋找最好的方式來成功後禁用DataGridView的一行Drag & Drop操作。 因此,我已經放棄了該行並將其標記爲使用背景顏色移動。如何禁用從C#和Winforms中的DataGridView的特定行拖動?

現在我需要進一步禁用拖動&放在同一行。這可能沒有刪除行?

我可以去選擇一個下降的DataGridView列,但我不能將其標記爲不是「拖動」:

dgvToolPosition.Rows[dgvToolPosition.SelectedRows[0].Index].Selected = false; 

是否有任何可能的方式來設置行的避免了插入屬性List<DataGridViewRowCollection>已刪除行的相應索引?

+0

不要調用DoDragDrop方法嗎? – LarsTech

+0

我想知道是否有一種方法將行標記爲不可拖動,否則我必須在列表上保存已經放棄的行索引以避免多次拖放。 – sentenza

回答

1

避免對以前下降了連續拖動事件的最好方法是檢查該行的唯一財產我在全成拖放操作(DefaultCellStyle.BackColor)設置:

// Check if a row in the current selection has a gray background color, 
// so it can be skipped on Drag&Drop. 
       foreach(DataGridViewRow selectedRow in dgvToolPosition.SelectedRows) 
       { 
        if(selectedRow.DefaultCellStyle.BackColor == FCSCoreGlobal.ColorGray) 
         return; 
} 

我知道這是不是做到這一點的最好辦法,但是到現在爲止這是我已經找到了最好的伎倆。我仍然在尋找DataGridViewRow上的AllowDrag屬性設置爲false。

相關問題