DataGridView中CellClick的使用,选中一行触发的动作可以在这个方法里执行

view sourceprint?private void dataGridView2_CellClick(object sender, DataGridViewCellEventArgs e)    

        {                      

            pnlBottom.Enabled = true;                  //获得当前选中的行    

            int rowindex = e.RowIndex;    

            string value0="";    

            string value1 = "";    

            string value2 = "";    

            try  

            {    

                 //获得当前行的第一列的值    

                value1= dgvHome.Rows[rowindex].Cells[1].Value.ToString();    

                            //获得当前行的第0列的值    

                value0 = dgvHome.Rows[rowindex].Cells[0].Value.ToString();    

                 //获得当前行的第二列的值    

                value2 = dgvHome.Rows[rowindex].Cells[2].Value.ToString().Trim();    

              MessageBox.show("第0列的值:{0};第一列的值:{1};第二列的值:{2}",value0,value1,value2);    

           }    

            catch (Exception exc) { }    

              

        }   

你可能感兴趣的:(datagridview)