如何使用同一个的函数逻辑来处理不同id的datagridview控件?

tylrr123 tylrr123 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
大伙好, 我的c#程序里面有5个 datagirdview 控件,需要使用同样的处理逻辑来显示数据。 我想使用一个showdata函数来处理这五个 datagirdview 控件。请问 应该怎么写呢? 我的思路是是 在showdata里面写一个参数,把需要显示的控件名作为参数传递进来处理。但是不知道怎么写,请指点 谢谢。
//下面这段是处理dataGridViewX4控件的代码。我想把它改成可以处理全部5个 dataGridViewX控件的showdata函数。


private void dataGridViewX4_DataBindingComplete(object sender, DataGridViewBindingCompleteEventArgs e)
{
//所以行号的背景色
for (int i = 0; i < this.dataGridViewX4.Rows.Count; i++)
{
if (i % 2 == 0)
{
dataGridViewX4.Rows[i].DefaultCellStyle.BackColor = Color.Lavender; //偶数行浅蓝色
}
}
}

private void dataGridViewX4_CellMouseEnter(object sender, DataGridViewCellEventArgs e)
{
if (e.RowIndex > 0)
dataGridViewX4.Rows[e.RowIndex].DefaultCellStyle.BackColor = Color.Khaki;
return;
}

private void dataGridViewX4_CellMouseLeave(object sender, DataGridViewCellEventArgs e)
{
if (e.RowIndex > 0)
{
if (e.RowIndex % 2 == 0)
{
dataGridViewX4.Rows[e.RowIndex].DefaultCellStyle.BackColor = Color.Lavender; //偶数行浅蓝色
}
else
dataGridViewX4.Rows[e.RowIndex].DefaultCellStyle.BackColor = Color.White;
}
return;
}






谢谢指点~~~
...全文

相关推荐

评论 3
收藏 已收藏
分享
返回顶部
tylrr123
C# 111,130 成员 642,540 内容