DataGridView的知識

DataGridView的幾個基本操作:
1、獲得某個(指定的)單元格的值:
dataGridView1.Row[i].Cells[j].Value;
2、獲得選中的總行數:
dataGridView1.SelectedRows.Count;
3、獲得當前選中行的索引:
dataGridView1.CurrentRow.Index;
4、獲得當前選中單元格的值:
dataGridView1.CurrentCell.Value;
5、取選中行的數據
string[] str = new string[dataGridView.Rows.Count];
for(int i;i<dataGridView1.Rows.Count;i++)
{
if(dataGridView1.Rows[i].Selected == true)
{
str[i] = dataGridView1.Rows[i].Cells[1].Value.ToString();
}
}
7、獲取選中行的某個數據
int a = dataGridView1.SelectedRows.Index;
dataGridView1.Rows[a].Cells["你想要的某一列的索引,想要幾就寫幾"].Value;
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章