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

How do I map column of sfDataGrid to datasource (BindingSource) in design time?

public class myData : IEditableobject
    {
        public string name { get; set; }
        public Int32 age {get;set;}
       
        public string value { get; set; }
...

    }

-- Design time
1. I have created myBindingSource for MyData and linked it to DataSource of sfDataGrid.
2. I created columns of sfDataGrid and set MappingName to property name of MyData.
3. I added some code.

        List arr = new List(); 
             private void Form1_Load(object sender, EventArgs e)
        {
            
          //add sample data
            arr.Add(   new myData(){ name = "Hell2o", age = 32, value = "hasdjasd" });
            arr.Add(  new myData(){ name = "Hello3", age = 12, value = "hasdjasd" }  );
            arr.Add(new myData() { name = "Hello4", age = 13, value = "hasdjasd" });

            myDataBindingSource.DataSource = arr;
           }

myDataBindingSource is connected to DataGridView control too.

When I run the project, sfDataGrid does not show any data but DataGridView shows all data.

I know I can do it with code but I don't want to add code for visual property setting.
I'd like to finish visual design in ide as possible as I can.

I tried  GridGroupingControl but it does not have RowValidation event.


1 Reply

SS Susmitha Sundar Syncfusion Team August 19, 2019 03:21 PM UTC

Hi, 
 
Thank you for using Syncfusion controls. 
 
We could able to reproduce your reported query” SfDataGrid datasource not updated when set the bindingsource at Form_Load event”. We recommed to set the SfDataGrid datasource in Form_Load event. Please refer the following code snippet, 
C#: 
BindingSource bindingSource; 
public Form1() 
{ 
     InitializeComponent(); 
      
     bindingSource = new BindingSource(); 
    this.Load += Form1_Load; 
} 
 
List<OrderInfo> list = new List<OrderInfo>(); 
private void Form1_Load(object sender, EventArgs e) 
{ 
     list.Add(new OrderInfo(1001, "Maria Anders", "Germany", "ALFKI", "Berlin")); 
     list.Add(new OrderInfo(1002, "Ana Trujilo", "Mexico", "ANATR", "Mexico D.F.")); 
     list.Add(new OrderInfo(1003, "Antonio Moreno", "Mexico", "ANTON", "Mexico D.F.")); 
     list.Add(new OrderInfo(1004, "Thomas Hardy", "UK", "AROUT", "London")); 
     list.Add(new OrderInfo(1005, "Christina Berglund", "Sweden", "BERGS", "Lula")); 
     bindingSource.DataSource = list; 
     this.sfDataGrid1.DataSource = bindingSource; 
      
 } 
 
GridGroupingControl does not provide support for Rowvalidation event. SfDataGrid provide this support. Please refer following user guide documentation, 
 
 
Please contact us for further assistance. 
 
Regards, 
Susmitha S 


Loader.
Live Chat Icon For mobile
Up arrow icon