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. Image for the cookie policy date
close icon

Column '[ColumnName]' Duplicates are not allowed

I create a simple form for searching and grouping result. Like this: 

        public void InitializeData()
        {
            //Setup GridGroupingControl
            //Setup DataSource
            this.ggcStockResult.DataSource = _stockService.GetStockBalanceDataTable(_parameters);

            //Setup GroupArea
            this.ggcStockResult.ShowGroupDropArea = true;
             this.ggcStockResult.TableDescriptor.GroupedColumns.Add("ProductCode");
            this.ggcStockResult.TableDescriptor.GroupedColumns.Add("WarehouseCode");
        }

        private void btnSearch_Click(object sender, EventArgs e)
        {
            InitializeData();
        }


When click search button, it shows results and group correctly. A problem occur when I click search again, it throw exception like this "Column 'ProductCode' Duplicates are not allowed"
Do you have any suggestion to resolve this?

1 Reply

AK Adhikesevan Kothandaraman Syncfusion Team September 9, 2015 11:30 AM UTC

HI CHAIRAT,

On second clicking the Search button which will only reset the DataSource of the Grid, but the TableDescriptor objects are not disposed. Hence, it throws the “Duplicates are Not allowed” exception. To avoid the exception, clear the GroupedColumns collection before adding. Please refer to the below code example,

Code snippet :

        public void InitializeData()
        {
            //Setup GridGroupingControl
            //Setup DataSource
            this.ggcStockResult.DataSource = _stockService.GetStockBalanceDataTable(_parameters);

            //Setup GroupArea
            this.ggcStockResult.ShowGroupDropArea = true;

            //Clear the GroupedColumns
     this. ggcStockResult.TableDescriptor.GroupedColumns.Clear();
             this.ggcStockResult.TableDescriptor.GroupedColumns.Add("ProductCode");
            this.ggcStockResult.TableDescriptor.GroupedColumns.Add("WarehouseCode");
        }

        private void btnSearch_Click(object sender, EventArgs e)
        {
            InitializeData();
        }

Regards,
Adhi.


Loader.
Live Chat Icon For mobile
Up arrow icon