【问题标题】:How to bind data to SyncFusion GridControl in C# using Windows Application?如何使用 Windows 应用程序将数据绑定到 C# 中的 SyncFusion GridControl?
【发布时间】:2014-06-03 02:22:30
【问题描述】:

我受够了这个 Syncfusion Controls,与普通的 datagridview 相比,这些都非常困难。 Syncfusion GridControl 中的 Datapropertyname 在哪里。如何将数据绑定到网格控件。

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;

通过使用上面的代码,我无法绑定它,我没有进入他们的任何链接。

【问题讨论】:

  • 我不太了解这些控件,但看起来您绑定的是 styles 而不是 data。有gridControl1.DataSource 属性吗?
  • @EvanL 你认为我不熟悉 Windows 控件。我很清楚。对于datagridview,我们写DataGridView.DataSource,但这里没有机会。因为我给了这样的
  • 我们这里显然有语言障碍。我是说我不知道这个控件。并询问它是否具有该属性。显然不是。抱歉,我帮不了你更多。

标签: c# winforms data-binding gridcontrol syncfusion


【解决方案1】:

正如 Doug 所建议的,数据绑定的最佳方式是使用 GridGrouping 或 GridDataBound 控件。如果您仍想使用 GridControl,那么我们建议您使用 PopulateValues 方法来绑定数据。详情请参考以下代码sn-p和UG链接。

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链接: http://help.syncfusion.com/ug/windows%20forms/grid/documents/thegridcontrolpopula.htm

您还可以使用虚拟网格将数据绑定到您的网格。虚拟网格可以极快地显示大量数据。有关虚拟网格的更多详细信息,请参阅下面的 UG 链接。

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

问候, 阿尼什

【讨论】:

    【解决方案2】:

    您似乎使用了错误的网格控件。使用Syncfusion.Windows.Forms.Grid.Grouping.GridGroupingControlSyncfusion.Windows.Forms.Grid.GridDataBoundGrid 控件进行直接数据绑定。

    如果你真的想使用Syncfusion.Windows.Forms.Grid.GridControl,那么你可以在虚拟模式下使用它。查看QueryColCountQueryRowCountQueryCellInfoQueryCellFormattedText 事件。 QueryCellInfo 是您应该设置样式和值的地方。如果你想做双向绑定,也可以查看SaveCellInfo 事件。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-04-11
      • 1970-01-01
      • 1970-01-01
      • 2012-06-21
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多