DataGridView几个高级方法
格行换色功能添加DataBindingComplete事件
private void dataGridView1_DataBindingComplete(object sender, DataGridViewBindingCompleteEventArgs e)
{
for (int i = 0; i < this.dataGridView1.Rows.Count; i++)
{
DataGridViewRow row = this.dataGridView1.Rows;
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.Cells.Count; i++)
{
StringBuilder builder = new StringBuilder();
builder.AppendFormat("行数据基本信息", new object);
for (int j = 0; j < this.dataGridView1.Rows.Cells.Count; j++)
{
if (this.dataGridView1.Columns.Visible)
{
DataGridViewCell cell = this.dataGridView1.Rows.Cells;
builder.AppendFormat(" {0}:{1}\r\n", this.dataGridView1.Columns.HeaderText, cell.Value);
}
}
this.dataGridView1.ToolTipText = builder.ToString();
}
}
catch
{
}
}
private void dataGridView1_RowLeave(object sender, DataGridViewCellEventArgs e)
{
for (int i = 0; i < this.dataGridView1.Rows.Cells.Count; i++)
{
this.dataGridView1.ToolTipText = string.Empty;
}
}
学习一下 感谢分享! good~謝謝分享~ good~謝謝分享~ 谢谢楼主了 谢谢谢,不错的高级高级方法 感谢分享,学习提高 谢谢分享 隔行换色其实有更简单的办法,datagridview 有奇数行的属性,所以这样设置就行。
dataGridView1.AlternatingRowsDefaultCellStyle.BackColor = Color.AliceBlue;//奇数列 bucuo 谢谢分享啊 good~謝謝分享~ 不错,学习中,谢谢分享
页:
[1]