We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. (Last updated on: November 16, 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

How to check duplicates for a column using GridDataBoundGrid using C#2010?

Thread ID:

Created:

Updated:

Platform:

Replies:

116222 Apr 29,2014 06:08 AM UTC May 10,2014 09:35 AM UTC WinForms 1
loading
Tags: GridDataBoundGrid(Classic)
Venkata
Asked On April 29, 2014 06:08 AM UTC

Hi there, I am doing Checking duplicates by using the following code in Normal Datagridview

    if (dgvwDtls.Columns[this.dgvwDtls.CurrentCell.ColumnIndex].Name == "Column2")
            {
                if (!string.IsNullOrEmpty(e.FormattedValue.ToString()))
                {
                    foreach (DataGridViewRow dgvwRw in dgvwDtls.Rows)
                    {
                        if (e.RowIndex != dgvwRw.Index)
                        {
                            if (e.FormattedValue.ToString() == dgvwRw.Cells["Column2"].FormattedValue.ToString())
                            {
                                MessageBox.Show(e.FormattedValue.ToString() + " is already entered", Classes.Gnrlprps._MsgCptn);
                                dgvwRw.Cells["Column2"].Value = string.Empty;
                                e.Cancel = true;
                                return;
                            }
                        }
                    }
                }
            }

But in sync fusion how to use foreach, i just tried like this
 GridCurrentCell cc = this.gdbgrDtls.CurrentCell;
            if (cc.ColIndex == 2)
            {
                if (!string.IsNullOrEmpty(this.gdbgrDtls[cc.RowIndex, cc.ColIndex].FormattedText))
                {
                    foreach (DataGridViewRow dgvwRw in dgvwDtls.Rows)
                    {
                        if (e.RowIndex != dgvwRw.Index)
                        {
                            if (e.FormattedValue.ToString() == dgvwRw.Cells["Column2"].FormattedValue.ToString())
                            {
                                MessageBox.Show(e.FormattedValue.ToString() + " is already entered", Classes.Gnrlprps._MsgCptn);
                                dgvwRw.Cells["Column2"].Value = string.Empty;
                                e.Cancel = true;
                                return;
                            }
                        }
                    }
                }
            }


Solai A L [Syncfusion]
Replied On May 10, 2014 09:35 AM UTC

Hi Venkata,

 

Sorry for the delay.

 

Kindly refer the below provided code snippet and sample  for validating the cell duplicates. We have prepared the code snippet similar to the one provided by you. In this code we have checked the values of a specific column with the current cell. Please let us know whether the given solution achieves your requirement.

 

 

void gridDataBoundGrid1_CellClick(object sender, Syncfusion.Windows.Forms.Grid.GridCellClickEventArgs e)

        {

            GridCurrentCell cc=this.gridDataBoundGrid1.CurrentCell;

            if (e.ColIndex == 1)

            {

                if (!string.IsNullOrEmpty(this.gridDataBoundGrid1[cc.RowIndex, cc.ColIndex].FormattedText))

                {

                    for (int i = 0; i < gridDataBoundGrid1.Model.RowCount;i++ )

                    {

                        if(e.RowIndex!=i)

                        {

                            if (this.gridDataBoundGrid1[cc.RowIndex, cc.ColIndex].CellValue.ToString() == gridDataBoundGrid1[i, e.ColIndex].CellValue.ToString())

                            {                                                  

                                MessageBox.Show(this.gridDataBoundGrid1[cc.RowIndex, cc.ColIndex].CellValue.ToString() + " is already entered");

                                this.gridDataBoundGrid1[cc.RowIndex, cc.ColIndex].CellValue = string.Empty;

                                e.Cancel = true;

                                return;

                            }

                        }

                    }

                }

            }

        }

 

Please let us know if you have any other concerns.

 

Thanks & Regards,

AL.Solai.


Attachment: WindowsFormsApplication8_ca49712b.zip

CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

;