datagridview

datagridview.Rows[].Cells[].value     取单元格值 

datagridview.CurrentCell.RowIndex;是当前活动的单元格的行的索引
DataGridView1.CurrentRow.Index 获得包含当前单元格的行的索引 
datagridview.SelectedRows 是选中行的集合
datagridview.SelectedColumns 是选中列的集合
datagridview.SelectedCells 是选中单元格的集合

datagridview.Rows[x].Selection=true 设定x行为选中状态

datagridview.FirstDisplayedScrollingRowIndex 显示在首行的索引

dataGridView1.Sort(dataGridView1.Columns[0], ListSortDirection.Ascending);//按列排序 dataGridView1.Rows[i].DefaultCellStyle.BackColor = Color.Green; //行背景色 dataGridView1.Rows[i].Cells[i].DefaultCellStyle.BackColor = Color.Green; //单元格背景色 dataGridView1.AlternatingRowsDefaultCellStyle.BackColor = Color.AliceBlue;//交替(间隔)背景色 //响应DataGridView鼠标点击事件,获得行号索引 private void dataGridView1_MouseDown(object sender, MouseEventArgs e) { if (e.Button == MouseButtons.Right) { DataGridView.HitTestInfo h = dataGridView1.HitTest(e.X, e.Y); Rowsindex=h.RowIndex; dataGridView1.ClearSelection(); dataGridView1.Rows[Rowsindex].Selected = true; } } ///////////////////////////////////////////////
posted @ 2016-11-29 13:18  clarklxr  阅读(122)  评论(0编辑  收藏  举报