datagridview中的选定行 [英] Selected Rows in datagridview
本文介绍了datagridview中的选定行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
hi
我想获取datagridview中选定行的行号.
请引导我...
hi
i wanna get row numbers selected rows in datagridview.
plz guide me ...
推荐答案
首先,您需要这样做;
First you show do this;
dataGridView1.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
这样,用户将选择整行而不是单元格.那么您可以通过foreach循环获得选定的行.
this way users will select the full row instead of the cells. then you can have the selected rows by an foreach loop.
foreach (DataGridViewRow r in dataGridView1.SelectedRows)
{
// do stuff
}
-OR-
第二路
检查 MSDN选定的行链接 [
-OR-
2nd way
Check the MSDN selected row link[^]
Good luck
尝试链接 [ ^ ]
引用此链接
http://msdn.microsoft.com/en-us/library/system.windows.forms.datagridview.selectedrows.aspx [ ^ ]
您也可以尝试这个
refer this link
http://msdn.microsoft.com/en-us/library/system.windows.forms.datagridview.selectedrows.aspx[^]
you can also try this
private void dataGridView1_RowEnter(object sender, DataGridViewCellEventArgs e)
{
DataGridViewRow currentRow = dataGridView1.SelectedRows;
ID = Convert.ToInt32(currentRow.Cells[0].Value);
textBox1.Text = Convert.ToString(currentRow.Cells[1].Value);
}
}
这篇关于datagridview中的选定行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文