datagridview选中多个单元格时触发什么事件呢?我想实现选中多个单元格时,得到第一行与最后一行的行号我要实现,只要用户进行了选中多个单元格的操作,就在文本框中显示出,选择单元格第一行的行号,和最后一行的行号。
关键不知道,纸型选中多个单元格时,触发什么事件呢?

解决方案 »

  1.   

    本帖最后由 bdmh 于 2012-03-29 10:00:32 编辑
      

  2.   


    private void dataGridView1_SelectionChanged(object sender, EventArgs e)
            {
                List<int> lstIndex = new List<int>();
                foreach (DataGridViewTextBoxCell cell in dataGridView1.SelectedCells)
                {
                    if (!lstIndex.Contains(cell.RowIndex))
                    {
                        lstIndex.Add(cell.RowIndex);
                    }
                }
                if (lstIndex.Count > 0)
                {
                    lstIndex.Sort();
                    //第一行
                    int firstRow = lstIndex[0];
                    //最后行
                    int lastRow = lstIndex[lstIndex.Count - 1];
                }
            }