Custom Data Binding to Grid and TableStyles

S

sandman

I've got some custom classes that implement IBindingList so I can bind
them to a DataGrid. My test app works fine. So then I tried to format
the columns - I have a function that creates a TableStyles object,
formats all the columns, set the headers, column width, column order,
etc. I tried calling it in the form constructor after
InitializeComponent, I tried calling it in the Form_Load() event
handler. I tried calling it before I bound the custom class to the data
grid. But the grid just ignores my settings. I can't even figure out how
it's deciding what order to display the columns. Does anybody know
where/how I can override whatever the grid is doing by default?

margaret
 
D

Dmitriy Lapshin [C# / .NET MVP]

Hi,

Esnure you bind the grid AFTER (with the SetDataBinding method!) you have
initalized it with the TableStyles. As far as I remember, it doesn't work
the other way around.
 
K

KW

You also need to set the MappingName of the TableStyle to the name of
your Custom Class. So, if your custom collection class is called
'MyCollectionClass', set the mapping name to that. The same thing
applies if you were using dataviews or datasets to bind to a grid, but
you would instead use the name of the table in the dataview, or dataset.
Hope this helps.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top