private void dataGridView1_DragDrop(object sender, DragEventArgs e)
        {
            if (e.Data.GetDataPresent(typeof(DataGridViewRow)))
            {                UserLogin user = Login.GetLogin();
                Invite.InviteM(user.SessionId, DBHelper.userId);//发送邀请信息
            }        }得到的DataGridViewRow里有一列Id,怎么把这列id读取出来?

解决方案 »

  1.   

    要得到某一行ID的值,比如第I行,ID所在的列是第一列,那么ID的值就是
    datagridview.rows[i].cell[0].tostring()
      

  2.   

    用这个行不?:DataGridView1.SelectedRows(0).Cells("Id").Value 
      

  3.   

    取得当前行的Id:
    int QuestionId = Convert.ToInt32(dataGridView1.CurrentRow.Cells["ColumnId"].Value.ToString());
    遍历所有行,获取checkBox选中的Id
    foreach (DataGridViewRow dr in dataGridView1.Rows)
                {
                    if (dr.Cells[0].Value != null)
                    {
                        if ((bool)dr.Cells[0].Value == true)
                        {
                            int Id = Convert.ToInt32(dr.Cells["ColumnId"].Value.ToString());
                            string State = dr.Cells["ColumnState"].Value.ToString();
                        }
                    }
                }