dataGridView保存选中的单元格的值

来源:互联网 发布:linux显卡驱动安装 编辑:程序博客网 时间:2024/04/28 07:33

 private void dataGridView1_CellMouseClick(object sender, DataGridViewCellMouseEventArgs e)        {            DataGridViewRow row = dataGridView1.CurrentRow;//获取选中的行数            try            {                if (e.RowIndex > -1)//是否有数据存在                {                    ID.Text = row.Cells[0].Value.ToString();                    name.Text = row.Cells[1].Value.ToString();                    name_py.Text = row.Cells[2].Value.ToString();                    JG.Text = row.Cells[3].Value.ToString();                    jgpy.Text = row.Cells[4].Value.ToString();                }            }            catch             {                MessageBox.Show("无数据");            }        }
为什么在判断的时候为-1而不为0   在dataGridView无数据时为0  。

0 0
原创粉丝点击