怎么做能带到以下效果:
单击DataGridView的一个单元格,返回此单元格所在行的某个单元格中的值?
例如;我单击DataGridView上的第3行第3列,DataGridView选中第3行,并且获取第3行中我想要的那个单元格中的值。
望多多指教,谢谢^_^
单击DataGridView的一个单元格,返回此单元格所在行的某个单元格中的值?
例如;我单击DataGridView上的第3行第3列,DataGridView选中第3行,并且获取第3行中我想要的那个单元格中的值。
望多多指教,谢谢^_^
string aa = this.dataGridView.Rows[2].Cells[2].Value.ToString();
吧?
计数都是从0开始计的
单击获取单元格的值:
private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
{
object objCellValue = this.dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex].Value;
}
{
string str= this.dataGridView1.Rows[2].Cells[2].Value.ToString();
}
写到datagridview的鼠标单击单元格内容事件CellContentClick里:
label.Text = dataGridView.SelectedCells[0].Value.ToString();//获取鼠标点击的单元格,赋值给label,lz自己改为其他的
string sp = zdwh.CurrentRow.Cells[3].Value.ToString(); //zdwh datagridview名称这是我工作的时候用的方法,希望对你有用
object objCellValue = this.dataGridView1.Rows[e.RowIndex].Cells[0].Value;
然后把objCellValue放到我需要的地方,进行转换就可以了。
object objCellValue = this.dataGridView1.Rows[e.RowIndex].Cells[0].Value;
然后把objCellValue放到我需要的地方,进行转换就可以了。
int aa=convert.toint32(dtg[dtg.currentcell.columnindex,dtg.currentcell.rowindex]);