您的位置首页百科知识

c#中如何DataGridView选中行的值?

c#中如何DataGridView选中行的值?

可以设置DataGridView的SelectionMode属性为FullRowSelect 实现左键点击选取整行,右击的话就需要在鼠标点击事件里面实现了如下:private void dataGridView1_CellMouseClick(object sender, DataGridViewCellMouseEventArgs e){if (e.ColumnIndex < 0 || e.RowIndex < 0) return;if (e.Button == System.Windows.Forms.MouseButtons.Right){dataGridView1.Rows[e.Row

代码如下: private void dataGridView1_CellClick(object sender,DatasGridViewEventArgs e){ String str=dataGridView1.Rows[e.Index].Cells["列名称"].Value.ToString();}

可以设置DataGridView的SelectionMode属性为FullRowSelect 实现左键点击选取整行,右击的话就需要在鼠标点击事件里面实现了 如下: private void dataGridView1_CellMouseClick(object sender, DataGridViewCellMouseEventArgs e) { if (e.ColumnIndex < 0 || e.RowIndex < 0) return; if (e.Button == System.Windows.Forms.MouseButtons.Right) { dataGridView1.Row

可以设置DataGridView的SelectionMode属性为FullRowSelect 实现左键点击选取整行,右击的话就需要在鼠标点击事件里面实现了 如下: private void dataGridView1_CellMouseClick(object sender, DataGridViewCellMouseEventArgs e) { if (e.ColumnIndex < 0 || e.RowIndex < 0) return; if (e.Button == System.Windows.Forms.MouseButtons.Right) { dataGridView1.Row

赞同一楼的做法.选定FullRowSelect.