Home › Forums › WinForms controls › Xceed Grid for WinForms › Empty grid after databinding..
-
AuthorPosts
-
#15861 |
Out of the blue the grid no longer binds correctly. Here is sample code:
With Grid
.BeginInit()
.DataSource = dt
.EndInit()
End WithThis code has worked fine for a while. Now all of the sudden my grid shows 0 datarows, however, if I set a breakpoint right after end init I see the datatable (dt) has rows, but the xceed grid datarows is empty.
What is even more strange is that I put a regular DataGridView on the form and bound to that right before the BeginInit of the xceed grid binding and for some reason that makes it work. I have no clue why binding to something else before binding to the xceed grid would make a difference but it does.
Any suggestions would be great.
Imported from legacy forums. Posted by jdanko (had 3187 views)
I tried pretty much the same code as you and it worked fine.
<code>
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
With GridControl1
.BeginInit()
.DataSource = GetTable()
.EndInit()
End WithEnd Sub
Private Function GetTable() As DataTable
‘Create a DataTable
Dim dt As New DataTable()
Dim dcId As New DataColumn()
dcId.ColumnName = “ComplexId”
dcId.DataType = System.Type.[GetType](“System.Int64”)
dt.Columns.Add(dcId)Dim dcName As New DataColumn()
dcName.ColumnName = “ComplexName”
dcName.DataType = System.Type.[GetType](“System.String”)
dt.Columns.Add(dcName)
For i As Integer = 0 To 49Dim row As System.Data.DataRow = dt.NewRow()
row(“ComplexId”) = i
row(“ComplexName”) = i.ToString() + “%”
dt.Rows.Add(row)
NextReturn dt
End Function
</code>Imported from legacy forums. Posted by CharlesB (had 184 views)
Yes, well I can make a simple app like that and it works. For some reason with all of the code I have something makes it not work. I was wondering if you had any ideas. I can make it work perfectly fine if i add the following line of code:
dt = GetTable()
DataGridView1.DataSource = dt
With XceedGrid
.BeginInit()
.DataSource = dt
.EndInit()
End WithFor some reason binding it to a datagridview before binding it to the xceed grid does something to the datatable or some action that resolves the problem. Is there anything that might need changed on my datatable?
Imported from legacy forums. Posted by jdanko (had 396 views)
The issue could be related to the DataMember not being explicitly set at this point.
Instead of using the DataSource property to set the source, you could use the SetDataBinding method. It will directly set both the DataSource and the DataMember.
Imported from legacy forums. Posted by CharlesB (had 4042 views)
-
AuthorPosts
- You must be logged in to reply to this topic.