I have manually defind a schema for a grid and specified that it will be bound at runtime. At runtime I fill a data table using a SQL statement being sure that the grid column keys match the data field names and then set the grid datasource to the datatable with the SetDataBindings method. I have also tried just setting the datasource. After the datasource is set, I can query the rows and columns of the grid in the immediate window and they contain data, the row count for the grid is correct and the keys and captions are correct. The problem is that all that displays on the grid is a blue background. No columns and no data.
I'm an old vb6 coder but new to .NET and the Ultragrid control so I assume I missed something in the setup. Can someone help, please?
If the grid is showing no columns, then it's not able to get a structure from the data source. That seems very odd if you are binding to a DataTable.Even if the data structure you defined at design-time did not match up to the DataTable you are binding to at run-time, what would happen is that the grid would throw away the design-time layout in favor of it's new data source. So if the grid is completely blank, then the only way that could happen is if the DataTable has no columns.
The only other way that this could happen that I can think of is that you turned off the grid's painting by calling BeginUpdate on the grid and you never called EndUpdate.
Have you tried binding the same DataTable to the DataGridView control? If not, it might be worth trying it just to see what happens.
Thank you Mike. I tried the DataGridView with the same datasource and all of the data showed up. After further hair pulling I found it. It must be a .net rookie move. I was defining the data table for the grid with the Using - End Using construct and was testing the values in the table and grid within the construct where they were there and accurate. As soon as execution hit the End Using it disposed of the data table which cleared the datasource for the grid. I switched to a Dim for the data table and it works fine.
Your comment ' if the grid is completely blank, then the only way that could happen is if the DataTable has no columns' made me look at the table further.
Thanks again.
Ah, okay. That makes perfect send. If you were creating the table inside a 'using' statement, then the table gets disposed when that code block ends. Binding is a continuous process, so you cannot dispose of the grid's data source while it's still using it.
It is a good idea to dispose of the DataTable when it's no longer needed, though. The OnDispose method of the form the grid is on it probably a good place for that.