我有一个DataGridView
(tblLoggedJobs)显示用户记录的作业列表.我需要管理员能够更新这些作业以显示作业的任何更新,或者注意作业是否已关闭.我希望程序将所选ROW中的数据显示到右侧的文本框中,但是我不确定如何获取此数据并根据所选行显示它.
Isw*_*San 11
您可以使用SelectedRows属性.
例:
if(dataGridView1.SelectedRows.Count > 0) // make sure user select at least 1 row
{
string jobId = dataGridView1.SelectedRows[0].Cells[0].Value + string.Empty;
string userId = dataGridView1.SelectedRows[0].Cells[2].Value + string.Empty;
txtJobId.Text = jobId;
txtUserId.Text = userId;
}
Run Code Online (Sandbox Code Playgroud)
在cellclick事件中添加代码
if (e.RowIndex >= 0)
{
//gets a collection that contains all the rows
DataGridViewRow row = this.dataGridView1.Rows[e.RowIndex];
//populate the textbox from specific value of the coordinates of column and row.
txtid.Text = row.Cells[0].Value.ToString();
txtfname.Text = row.Cells[1].Value.ToString();
txtlname.Text = row.Cells[2].Value.ToString();
txtcourse.Text = row.Cells[3].Value.ToString();
txtgender.Text = row.Cells[4].Value.ToString();
txtaddress.Text = row.Cells[5].Value.ToString();
}
Run Code Online (Sandbox Code Playgroud)
有关更多信息,请使用此链接如何使用C#将Datagridview中的选定行显示到文本框中
归档时间: |
|
查看次数: |
57305 次 |
最近记录: |