【问题标题】:fill specific column gridcontrol devexpress填充特定列 gridcontrol devexpress
【发布时间】:2016-08-16 07:08:32
【问题描述】:

我想填充网格视图中的特定列。我想用代码做到这一点,但是我已经在gridcontrol中建立了列,就像你在图片中看到的那样。

established Column

这是我填充列的代码,但我不知道如何使用名称或字段名或其他任何方式填充特定的一列。

GridControl1.DataSource = Nothing

SQL.ExecQuErY("SELECT nombre FROM productos")

If Not String.IsNullOrEmpty(SQL.Exception) Then MsgBox(SQL.Exception) : Exit Sub

For Each row As DataRow In SQL.DBDS.Tables(0).Rows

        ?????? THIS IS WHERE IT'S SUPPOSED TO GO THE INSTRUCTION TO FILL THE COLUMN ??????

Next

【问题讨论】:

  • 你试过用GridControl1.DataSource = SQL.DBDS.Tables(0)替换你的for循环吗?那应该将数据绑定到您的网格。无需逐行复制。
  • @FloatingKiwi 是的,谢谢,实际上,当我在 gridview 中没有列时,这就是我用来填充 gridcontrol 的方式,但我想填充用查询数据建立的特定列.
  • Devexpress 非常接近 windows 网格,所以我要做的是设置 DataGridView1.AutoGenerateColumns = falsemyColumn.DataPropertyName = "nombre",它应该为你设置绑定。

标签: vb.net gridview devexpress xtragrid gridcontrol


【解决方案1】:

尝试像这样将数据绑定到您的网格:

Sql.ExecQuErY("SELECT nombre As colNombre FROM productos")
GridControl1.DataSource = Sql.DBDS.Tables(0)

GridControl 中列的FieldName 必须与DataSource 中的字段名称相同。

或者您可以将GridControl 中列的FieldName 更改为nombre 并使用您的初始查询:

Sql.ExecQuErY("SELECT nombre FROM productos")
GridControl1.DataSource = Sql.DBDS.Tables(0)

【讨论】:

  • 是的!这是我一直在寻找的答案,谢谢。效果很好!
【解决方案2】:

在另一个 SO 线程上引用此 answer

How to add new line of row in devexpress gridcontrol?(WinForms C#)

它可能会指导您正确的实施方式。您必须将一些支持数据源分配给网格控件,才能在运行时添加行并使用 SetRowCellValue 方法仅将一列值分配给网格。

有很多关于与此类实现相关的 DevExpress 支持的问题。请遵循以下参考:
Creating Columns and Binding Them to Data Fields
ColumnView.AddNewRow Method
Add new row to xtragrid through code Add New Row to GridView
Adding new row to gridview
Adding gridView columns at runtime GridView: Add column in runtime
how to add columns to xtragrid dynamically at runtime and also how to add repository items to those columns dynamically??

希望对您有所帮助..

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-10-26
    • 1970-01-01
    • 1970-01-01
    • 2013-11-04
    • 1970-01-01
    • 1970-01-01
    • 2019-04-14
    相关资源
    最近更新 更多