2012-06-09 29 views
0

我需要獲取DataGridView中SelectedCells中最高的ColumnIndex。c#winforms如何獲得最高ColumnIndex

int i = theHighestColumnIndexAmongSelectedCells。

或者

foreach (DataGridViewCell cell in dgv.SelectedCells) 
if cell.ColumnIndex is theHighest 
int i = cell.ColumnIndex. 

我會怎樣做呢?

回答

3

它使用LINQ Max()功能最簡單的方法:

int max = dgv.SelectedCells.Cast<DataGridViewCell>().Max(c => c.ColumnIndex); 
+0

三江源,shf301。有用。 – Bonaca