0

I'm using a DBML file to create a schema for an existing database and I'm also adding new classes into it. Using an overriden Context class I've made it so the new tables are created in the database as needed. The new context class works admirably.

However, I'm having a bit of trouble displaying it in a readable way to the user. I've only got Windows Forms at my disposal, so I'm using a DataGridView control.

I can create columns manually, sure. But I was hoping I could use data annotations in the model to make use of the automatic column generation capabilities.

I've added annotations to the DBML using a "buddy class", as presented here.

However, I seem to be missing something, as the DGV class generated default columns for all my fields, despite the fact that, in the data annotations, I've changed the display names of some, ordering and even prevented some fields from being auto-generated at all. Or so I thought, at least.

Any idea what I could be missing?

1 Answer 1

1

You can make code the uses Reflection to get the public properties. From there on use your annotations to select the properties that need to become columns.

Sign up to request clarification or add additional context in comments.

1 Comment

So, automatic use of data annotations with WinForm controls such as DGV is not an option? Reflection is a last resort for me.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.