如何使用csharp中的datagridivew验证每个单元格中的重复值 [英] how to validate repeated values in each cell using datagridivew in csharp
本文介绍了如何使用csharp中的datagridivew验证每个单元格中的重复值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何使用csharp中的datagridivew验证每个单元格中的重复值。如何验证并显示弹出消息。我验证但它没有工作。请帮助我。
我的代码如下;
how to validate repeated values in each cell using datagridivew in csharp. how to validate and show the pop up message. i validate but it is not working.please help me.
my code as follows;
if (e.KeyChar == 118 || e.KeyChar == 86)// v,V to paste
{
String Msg = "";
if (CopyString != "" && CopyString != null)
{
int irow = Convert.ToInt16(datagridView.CurrentCellAddress.Y.ToString());
for (int i = 2; i < datagridView.Columns.Count; i++)
{
if (datagridView[i, irow].Value != "" && datagridView[i, irow].Value != null)
{
if (datagridView[i, irow].Value.ToString().Trim() == CopyString.ToString().Trim())
{
Msg = "Course is already entered in " + datagridView.Columns[i].HeaderText;
}
}
}
//if (Msg.ToString() != null)
//{
// MessageBox.Show(Msg.ToString());
//}
//else
{
datagridView.CurrentCell.Value = CopyString.ToString();
}
}
e.Handled = true;
}
来自我上面的代码有什么错误帮助我。
from my above code what is the mistake help me.
推荐答案
在你之前在DataGridView中输入数据,从您的源中消除重复的请求。如果请求保存在List中,则使用Linq语句Distinct仅采用不同的值并将它们插入DataGridView的DataSource。
Before you enter the data in the DataGridView, from your source eliminate the duplicate requests. If the requests are saved in a List then use the Linq statement Distinct to take distinct values only and insert them in the DataSource of the DataGridView.
这篇关于如何使用csharp中的datagridivew验证每个单元格中的重复值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文