2016-08-16 82 views
0

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

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 
+0

你有没有试着用替换你的for循环'GridControl1.DataSource = SQL.DBDS.Tables(0)'。这应该将数据绑定到您的网格。不需要逐行复制。 – FloatingKiwi

+0

@FloatingKiwi是的谢谢,实际上,这是我用来填充gridcontrol时,我没有在gridview中的列已经,但我想填补具体查询的数据建立一列。 –

+0

Devexpress跟Windows网格非常接近,所以我会在这里设置'DataGridView1.AutoGenerateColumns = false'和'myColumn.DataPropertyName =“nombre”',它应该为你设置绑定。 – FloatingKiwi

回答

0

尝试将数据绑定到您的网格状这个:

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

列的GridControlFieldName必须DataSource有场相同的名称。

,或者你可以在GridControl更改列的FieldName到​​和使用您的初始查询:

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

是的!这是我正在寻找的答案,谢谢。它完美的工作! –

+0

我很高兴听到这个,谢谢你:) –

0

在另一个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??

希望这有助于..