C# 防止C1TrueDBGrid中的重复条目

C# 防止C1TrueDBGrid中的重复条目,c#,C#,我正在使用我的C#Windows应用程序,这是我第一次使用tdbgrid(component1)。我想防止用户在使用数据库验证后输入重复的值 以下是我在(BeforeColUpdate)事件中使用的代码: componentone回答我这个问题: private void c1TrueDBGrid1_BeforeColUpdate(object sender, C1.Win.C1TrueDBGrid.BeforeColUpdateEventArgs e) { if (e.ColIndex

我正在使用我的C#Windows应用程序,这是我第一次使用tdbgrid(component1)。我想防止用户在使用数据库验证后输入重复的值

以下是我在(BeforeColUpdate)事件中使用的代码:


componentone回答我这个问题:

private void c1TrueDBGrid1_BeforeColUpdate(object sender, C1.Win.C1TrueDBGrid.BeforeColUpdateEventArgs e)
{
    if (e.ColIndex == 1)
    {
       for (int i = 0; i < c1TrueDBGrid1.RowCount; i++)
       {
        if (c1TrueDBGrid1.Editor.Text == c1TrueDBGrid1[i, e.ColIndex].ToString())
        {
            MessageBox.Show("Sorry: but this item(s) already Exists", "Error Info", MessageBoxButtons.OK, MessageBoxIcon.Information);
            e.Cancel = true;
        }
    }
 }
}
private void c1TrueDBGrid1\u forecolupdate之前(对象发送方,C1.Win.C1TrueDBGrid.BeforeColUpdateEventArgs e)
{
如果(e.ColIndex==1)
{
对于(int i=0;i
链接:
希望这对以后的其他人有所帮助:

请格式化您的代码
private void C1TrueDBGrid_AfterColUpdate(object sender, C1.Win.C1TrueDBGrid.ColEventArgs e)
{
    if (!ExitValue)
    {
        int indexRow = this.C1TrueDBGrid.RowBookmark(this.C1TrueDBGrid.Row);
        this.C1TrueDBGrid[indexRow, 0] = CSystemUsers.GroupsCode;
        this.C1TrueDBGrid[indexRow, 0] = CSystemUsers.EngName;
    }
}
private void c1TrueDBGrid1_BeforeColUpdate(object sender, C1.Win.C1TrueDBGrid.BeforeColUpdateEventArgs e)
{
    if (e.ColIndex == 1)
    {
       for (int i = 0; i < c1TrueDBGrid1.RowCount; i++)
       {
        if (c1TrueDBGrid1.Editor.Text == c1TrueDBGrid1[i, e.ColIndex].ToString())
        {
            MessageBox.Show("Sorry: but this item(s) already Exists", "Error Info", MessageBoxButtons.OK, MessageBoxIcon.Information);
            e.Cancel = true;
        }
    }
 }
}