1.不同的page的页面的name属性可以进行判断,k如下:
TabControl.SelectedTab.Name.equals("name");
2.dataGridview选择某一行的实现方法:、
dgv.column[0].selected=true;
3datagridview的两种添加序号的写法,两种方法的不同之处在于最后的draw的方法不同,倾向于第二种方法
(1)双击RowPostPaint方法
private void dgv_RowPostPaint(object sender, DataGridViewRowPostPaintEventArgs e)
{
SolidBrush b = new SolidBrush(this.dgv.RowHeadersDefaultCellStyle.ForeColor);
e.Graphics.DrawString((e.RowIndex + 1).ToString(System.Globalization.CultureInfo.CurrentUICulture), this.dgv.DefaultCellStyle.Font, b, e.RowBounds.Location.X + 20, e.RowBounds.Location.Y + 4);
}
(2)双击RowPostPaint方法
private void dgv_RowPostPaint(object sender, DataGridViewRowPostPaintEventArgs e)
{
//自动编号,与数据无关
Rectangle rectangle = new Rectangle(e.RowBounds.Location.X,
e.RowBounds.Location.Y,
dgv.RowHeadersWidth - 4,
e.RowBounds.Height);
TextRenderer.DrawText(e.Graphics,
(e.RowIndex + 1).ToString(),
dgv.RowHeadersDefaultCellStyle.Font,
rectangle,
dataGridView_Manufacturer.RowHeadersDefaultCellStyle.ForeColor,
TextFormatFlags.VerticalCenter | TextFormatFlags.Right);
}