datagridview没有绑定数据源,就是单纯的向datagridview中输入一行数据,有4列.
输入的时候其中一列不能有重复,如果有重复,就提示.没有重复就写入.请问这个是否有重复的判断要怎么写? 希望知道的能讲的详细一点,谢谢各位了...

解决方案 »

  1.   

    遍历datagridview判断是否存在或使用datatable保存判断是否存在,再添加
      

  2.   

    你是在运行后,手动向dataGridView添加一行的某列时去判断时候有重复吗?
      

  3.   

    可以循环遍历datatable里面有没有重复的数据 让后再绑定
      

  4.   


            private void dataGridView1_CellValueChanged(object sender, DataGridViewCellEventArgs e)
            {
                int count = this.dataGridView1.Rows.Count;
                
                if (count > 1 && dataGridView1.CurrentCell.RowIndex>0)
                {                if (this.dataGridView1.CurrentCell.ColumnIndex == 1)
                    {
                        for (int i = 0; i <this .dataGridView1.CurrentCell .RowIndex ; i++)
                        {
                            if (this.dataGridView1.Rows[i].Cells[1].Value.ToString() == this.dataGridView1.Rows [this .dataGridView1 .CurrentCell .RowIndex ].Cells [1].Value .ToString ())
                            {
                                MessageBox.Show("此值重复了!!!","提示");
                                break;
                            }
                        }
                    }
                }
            }