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

Columns.Count == 0 after loading Data

Hello,
After loading data (sFDataGrid1.DataSource = list of data), I can't access to Columns collection and sFDataGrid1.Columns.Count == 0?
Columns are generated automatically,   sFDataGrid1.AutoGenerateColumns = true; 
Best Regards

5 Replies

DY Deivaselvan Y Syncfusion Team November 30, 2018 07:20 AM UTC

Hi Cosyspro, 

Thanks for contacting Syncfusion support. 

We have created a simple sample to reproduce the issue. But we are unable able to reproduce the reported issue at our end. Please have a look at the following code example and the provided sample that we have used to test the issue. 

Code example:  

sfDataGrid.AutoGenerateColumns = true; 
var data = new OrderInfoCollection(); 
sfDataGrid.DataSource = data.OrdersListDetails; 
var columnCount = this.sfDataGrid.Columns.Count; 
label1.Text = "Column Count - " + columnCount.ToString(); 


If still the issue exists, could you please try reproducing it in the above sample or send us the reproducing steps so that we could sort out the cause of the issue and provide you an exact solution at the earliest? 

Regards, 
Deivaselvan 



CO Cosyspro November 30, 2018 08:16 AM UTC

Hi Deivaselvan,
Thank you for your response.
I can't solve the problem. Here is my code:

          
           var query = from l in dbWork.Charges
                       select l;
            sfDataGrid.DataSource = (IEnumerable<Data.Charge>) query.ToList(); 

          sfDataGrid.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
            | System.Windows.Forms.AnchorStyles.Left)
            | System.Windows.Forms.AnchorStyles.Right)));
            sfDataGrid.AutoExpandGroups = true;
            sfDataGrid.AutoSizeColumnsMode = Syncfusion.WinForms.DataGrid.Enums.AutoSizeColumnsMode.Fill;
            sfDataGrid.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5);
            sfDataGrid.ShowGroupDropArea = true;
            sfDataGrid.AllowFiltering = true;
            sfDataGrid.AllowDeleting = false;
            sfDataGrid.AllowGrouping = true;
            sfDataGrid.AllowEditing = false;
            sfDataGrid.AutoGenerateColumns = true;           
            sfDataGrid.AllowResizingColumns = true;
            sfDataGrid.ShowRowHeader = true;
            sfDataGrid.EnableDataVirtualization = true;
            sfDataGrid.FilterPopupMode = Syncfusion.WinForms.GridCommon.FilterPopupMode.Both;
            sfDataGrid.GroupCaptionTextFormat = "{Key} : {ItemsCount}";
            sfDataGrid.Style.FreezePaneLineStyle.Color = System.Drawing.Color.BlueViolet;
            sfDataGrid.Style.FreezePaneLineStyle.Weight = 2;
            sfDataGrid.SelectionMode = Syncfusion.WinForms.DataGrid.Enums.GridSelectionMode.Multiple;
            sfDataGrid.SelectionUnit = Syncfusion.WinForms.DataGrid.Enums.SelectionUnit.Row;
            sfDataGrid.NavigationMode = Syncfusion.WinForms.DataGrid.Enums.NavigationMode.Cell;

Regards


DY Deivaselvan Y Syncfusion Team December 3, 2018 12:11 PM UTC

Hi Cosyspro, 

Thanks for your update. We have created a sample using the code provided by you and it is available in the following link. 


Still we are unable able to reproduce the reported issue at our end. We suspect that you may set AutoGenerateColumns property to false before assigning the DataSource to the DataGrid. You must enable SfDataGrid.AutoGenerateColumns property before assigning the DataSource to the DataGrid. 

It is hard for us to trace the exact cause of the issue without seeing the reported issue at our end in the sample. If still the issue exist, Is there any possible way for you to provide us with a sample that shows this issue? or reproduce the issue in above sample. It will be easier for us to have a closer look into the problem and resolve it. 

Regards, 
Deivaselvan 



CO Cosyspro December 3, 2018 10:02 PM UTC

Hi Deivaselvan,
Thanks for your response.
I set AutoGenerateColumns to true before loanding data to SfDataGrid.
I tested your example, it's work fine.
I don't understand where is problem in my code. But after searsh and many tries, I found the problem in the ShowBusyIndicator parameter when it is set to true!
I used this parameter in your example and it is work also fine! 
Regards


DY Deivaselvan Y Syncfusion Team December 4, 2018 09:34 AM UTC

Hi Cosyspro,

As you specified, we are unable to reproduce the issue at our end even by setting ShowBusyIndicator as true. So, kindly share your application to investigate further on the reported issue, thereby we could analyze further and update you with the appropriate solution at the earliest.

Regards,
Deivaselvan 


Loader.
Up arrow icon