2017-09-26 17 views
0

enter image description here在SourceGrid

從上面的圖片中獲取所選擇的開始和結束單元格位置,我希望得到兩個結果分別返回StartPoin(2,0)和EndPoint(4,2)。

我已搜索谷歌和stackoverflow,但沒有發現任何東西。

任何人有好主意嗎?

+1

提供你試過的代碼 – Praveen

回答

0

您可以嘗試使用您正在使用的控件的屬性SelectedCells。這是所有選定單元格的數組。

現在你需要找到最低RowIndexColumnIndex單元格(即起點),並與最高RowIndexColumnIndex細胞(即終點)。

應該是這樣的(你會發現在你的情況下使用的變量

僞代碼:。

Cell StartPoint = null; 
Cell EndPoint = null, 
foreach(Cell cell in gridControl.SelectedCells){ 
    if(StartPoint == null) 
     StartPoint = cell; 
    else if(cell.RowIndex <= StartPoint.RowIndex && cell.ColumnIndex <= StartPoint.ColumnIndex){ 
     StartPoint = cell; 
    } 
    if(EndPoint == null) 
     EndPoint = cell; 
    else if(cell.RowIndex >= EndPoint .RowIndex && cell.ColumnIndex >= EndPoint .ColumnIndex){ 
     EndPoint = cell; 
    } 
} 
+0

謝謝你的哥們! – ChiaHsien

+0

我看到你有選定的地區。檢查是否有一些屬性可以給你想要的結果。如果沒有,那麼你必須像上面的例子那樣手動找到它們。 –

0

經過多次嘗試

我終於得到了答案使用「[sourceGridName] .Selection.GetSelectionRegion()」方法。