How to bind data to SyncFusion GridControl in C# using Windows Application?

帅比萌擦擦* 提交于 2019-12-13 23:44:05

问题


i am fed up with this Syncfusion Controls, these are very difficult compared to normal datagridview. where is the Datapropertyname in Syncfusion GridControl. how to bind Data to Grid Control.

gridControl1.ColStyles[3].DataSource = dt1; 
gridControl1.ColStyles[3].DisplayMember = "bcmp_Name"; gridControl1.ColStyles[3].ValueMember = "bcmp_Id"; 
gridControl1.ColStyles[3].DropDownStyle = Syncfusion.Windows.Forms.Grid.GridDropDownStyle.Exclusive;
gridControl1.ColStyles[5].DataSource = dt2; 
gridControl1.ColStyles[5].DisplayMember = "bcmp_Name"; 
gridControl1.ColStyles[5].ValueMember = "bcmp_Id"; 
gridControl1.ColStyles[5].DropDownStyle = Syncfusion.Windows.Forms.Grid.GridDropDownStyle.Exclusive;
gridControl1.ColStyles[7].DataSource = dt3; 
gridControl1.ColStyles[7].DisplayMember = "bcmp_Name"; gridControl1.ColStyles[7].ValueMember = "bcmp_Id"; 
gridControl1.ColStyles[7].DropDownStyle = Syncfusion.Windows.Forms.Grid.GridDropDownStyle.Exclusive;
gridControl1.ColStyles[9].DataSource = dt4; 
gridControl1.ColStyles[9].DisplayMember = "bcmp_Name"; 
gridControl1.ColStyles[9].ValueMember = "bcmp_Id"; 
gridControl1.ColStyles[9].DropDownStyle = Syncfusion.Windows.Forms.Grid.GridDropDownStyle.Exclusive;
gridControl1.TableStyle.DataSource = Chldtbl;

By using the above code i am not able to bind it, i am not getting in any one of their links.


回答1:


It looks like you are using the wrong grid control. Use the Syncfusion.Windows.Forms.Grid.Grouping.GridGroupingControl or Syncfusion.Windows.Forms.Grid.GridDataBoundGrid controls for direct data binding.

If you really want to use the Syncfusion.Windows.Forms.Grid.GridControl, then you can use it in virtual mode. Look at the QueryColCount, QueryRowCount, QueryCellInfo, and QueryCellFormattedText events. QueryCellInfo is where you should set the styles and values. If you want to do do two-way binding, also see the SaveCellInfo event.




回答2:


As suggested by Doug, the best way for data binding is to use the GridGrouping or GridDataBound control. If you still want to use the GridControl then we suggest you to use the PopulateValues method for binding the data. Please refer the below code snippet and UG link for more details.

C#:
this.gridControl1.BeginUpdate();
this.gridControl1.RowCount = this.numArrayRows;
this.gridControl1.ColCount = this.numArrayCols;



// Call PopulateValues Method to move values from a given data source (this.initArray) into the Grid Range specified.
this.gridControl1.Model.PopulateValues(GridRangeInfo.Cells(1, 1, this.numArrayRows, this.numArrayCols), this.intArray);
this.gridControl1.EndUpdate();
this.gridControl1.Refresh();

UG link: http://help.syncfusion.com/ug/windows%20forms/grid/documents/thegridcontrolpopula.htm

Also you can make use of the Virtual Grid for binding data to your grid. Virtual grids can display large amounts of data extremely fast. Please refer the below UG link for more details regarding Virtual Grid.

UG Link: http://help.syncfusion.com/ug/windows%20forms/grid/documents/virtualgrids.htm

Regards, Anish



来源:https://stackoverflow.com/questions/23156420/how-to-bind-data-to-syncfusion-gridcontrol-in-c-sharp-using-windows-application

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!