1.DataGridViewCheckBoxColumn列点击更改选中状态
private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
{
DataGridViewCell cell = this.dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex];
if(cell.ColumnIndex==0)
{
DataGridViewCheckBoxCell rowcheck = (DataGridViewCheckBoxCell)dataGridView1.CurrentRow.Cells["colCheckBox"];
string vale = rowcheck.Value.ToString();//选中状态为“1”,未选中状态为“0”
if (vale=="1") { dataGridView1.CurrentRow.Cells["colCheckBox"].Value = "0"; }
else dataGridView1.CurrentRow.Cells["colCheckBox"].Value = "1";
}
}
2.添加行号
private void dataGridView2_RowPostPaint(object sender, DataGridViewRowPostPaintEventArgs e)
{
Rectangle rectangle = new Rectangle(e.RowBounds.Location.X,
e.RowBounds.Location.Y,
dataGridView2.RowHeadersWidth - 4,
e.RowBounds.Height);
TextRenderer.DrawText(e.Graphics, (e.RowIndex + 1).ToString(),
dataGridView2.RowHeadersDefaultCellStyle.Font, rectangle,
dataGridView2.RowHeadersDefaultCellStyle.ForeColor,
TextFormatFlags.VerticalCenter | TextFormatFlags.Right);
}
3.光标状态:箭头、转圈
this.Cursor = Cursors.WaitCursor;//转圈
this.Cursor = Cursors.Default;//箭头
4
dvAirwayPoint = new DataView(NDS.mdsNav_Ais_Route_Rte_Seg.Tables[0]);
dvAirwayPoint.Sort = "ROUTE_RTE_ID, VAL_SORT asc";
dvAirwayPoint.RowFilter = "ROUTE_RTE_ID = '" + airwayId + "'";