- 积分
- 33
- 在线时间
- 53 小时
- 主题
- 28
- 注册时间
- 2013-8-31
- 帖子
- 132
- 最后登录
- 2019-10-21
- 帖子
- 132
- 软币
- 3320
- 在线时间
- 53 小时
- 注册时间
- 2013-8-31
|
格行换色功能
添加DataBindingComplete事件
private void dataGridView1_DataBindingComplete(object sender, DataGridViewBindingCompleteEventArgs e)
{
for (int i = 0; i < this.dataGridView1.Rows.Count; i++)
{
DataGridViewRow row = this.dataGridView1.Rows[i];
if ((i % 2) != 0)
{
row.DefaultCellStyle.BackColor = Color.Gainsboro;
}
}
}
显示行数据信息功能
添加RowEnter和RowLeave事件
private void dataGridView1_RowEnter(object sender, DataGridViewCellEventArgs e)
{
try
{
for (int i = 0; i < this.dataGridView1.Rows[e.RowIndex].Cells.Count; i++)
{
StringBuilder builder = new StringBuilder();
builder.AppendFormat("行数据基本信息", new object[0]);
for (int j = 0; j < this.dataGridView1.Rows[e.RowIndex].Cells.Count; j++)
{
if (this.dataGridView1.Columns[j].Visible)
{
DataGridViewCell cell = this.dataGridView1.Rows[e.RowIndex].Cells[j];
builder.AppendFormat(" {0}:{1}\r\n", this.dataGridView1.Columns[j].HeaderText, cell.Value);
}
}
this.dataGridView1[i, e.RowIndex].ToolTipText = builder.ToString();
}
}
catch
{
}
}
private void dataGridView1_RowLeave(object sender, DataGridViewCellEventArgs e)
{
for (int i = 0; i < this.dataGridView1.Rows[e.RowIndex].Cells.Count; i++)
{
this.dataGridView1[i, e.RowIndex].ToolTipText = string.Empty;
}
}
|
评分
-
查看全部评分
|