使用 MS Visual Studio 和 C#.net 4.0。
所以,刚刚完成了我的程序的另一部分,它检查重复项,最终“非常感谢所有帮助”。向我的老板展示了喜欢它的人,然后问“他是否要选择显示具有重复值的零件号的 datagridview 的结果,是否可以突出显示与所选结果相等的 maindatagridview”。
现在首先我明白他的意思,但措辞相当困难,因此寻找一些例子让我开始非常困难。
现在虽然我没有任何代码,但我可以显示我目前拥有的代码。
我做的第一件事是在数据网格上识别一个事件处理程序,它可以检测选择了哪一行,我将使用“selectionchanged”。
更新:: 好的,虽然我会告诉你我重用我的代码的意思。请注意,代码非常相似,但只是一个起点,我可能会将以前的方法合并到新的方法中。
private void MyErrorGrid_SelectionChanged(object sender, EventArgs e)
{
string getPartSelected;
getPartSelected = MyErrorGrid.CurrentCell.Value.ToString();
foreach (DataGridViewRow row in ParetoGrid.Rows)
{
var cellValue = row.Cells["Keycode"].Value;
if (cellValue != null && cellValue.ToString() == getPartSelected)
{
ParetoGrid.Rows[row.Index].DefaultCellStyle.BackColor = Color.Red;
}
}
}
如您所见,这是可行的,但是存在一些问题。它突出显示但没有取消突出显示,所以我想我需要存储以前选择的?(不确定这是最好的方法)。
还需要添加导航,因为突出显示对用户来说不够好。At the moment ive added in selected = true but again when the selection changes i need to use the previous value.