I read the field metadata from a database table and create the columns at runtime and then bind the datagrid. It works fine most of the time. But sometimes. There will be a character off in the Metadata, so the grid comes up blank.
What I want to know is there any event to check for that when each column is bound, if there is an error on that binding to the column, you can grab it? Otherwise, I always have to visuallly look at each column name versus the table, and try to figure out which column didn't bind right.
You mentioned before setting the Grid to AutogenerateColumns, so that if it failed, it would use the default. The problem is, all my tables are generic, so showing the default layout would not be good.
So how would you suggest troubleshooting where a column generated dynammically in the FieldLayout is off from the BindingList it is being bound too?
Hi Cloepp -
There is no way for you to ‘trap an error’ to determine which column has the incorrect name since the situation you are describing is not an error condition from the grid's perspective.
What happens is, when the grid reads a record from the data source it tries to match it with a FieldLayout that is already in the FieldLayouts collection (the FieldLayouts in the collection will be a combination of ones that were AutoGenerated by the grid itself and those that were manually created by the developer). If it finds a FieldLayout where all the Fields and data types match, it uses it to display the data. If it does not find one that matches, it then checks the AutoGenerate property. If AutoGenerate is set to true it automatically generates a compatible FIeldLayout. If not, it essentially skips over the record because it cannot find a compatible FieldLayout.
One potential alternative approach if you are not able to ensure that your metadata is valid, is to manually create the Fields in your FieldLayout using UnboundField instead of Field (UnboundField is derived from Field), and set the Binding related fields on the UnboundField class instance to bind to the appropriate property on your data object. This way, if you specify an incorrect name for one of the fields only that column in the data will be blank (the other correctly-named Fields will show up ok), plus you will see a binding error in the ouput window with the incorrect field name.
Hope that helps.
I am just checking if you still require any assistance or clarification on the matter.