datagrid bound to IBindingList problem

  • Thread starter Thread starter Matthew Woods
  • Start date Start date
M

Matthew Woods

Hi, is there any way to format and order the columns displayed in a datagrid
bound to a class that inherits from IBindingList? i have used
DataGridTableStyle and added DataGridTextBoxColumns to it in the correct
order which works fine if the dataGrid.dataSource = "ArrayList", but it
doesn't work for my IBindingList wrapper.
If i bind the datasource to the arraylist method then the
ListChangedEventHandler is never invoked and my grid only updates if i
refresh the currencymanager or the grid itself but obviously this does not
satisfy the requirement of displying "live" data.

to summarise, i can update my grid live when bound to my IBindingList class
that wraps round my data class but i can't set the order of the columns at
runtime using DataGridTableStyle. Any hints (with examples) would be much
appreciated.

Thanks

Matt
 
If the style isn't being applied, then the style isn't being mapped
correctly to your datasource. You can have several styles bound to a grid,
but the one that gets used is when the MappingName of the style matches the
Name (ie: DataTable.Name) of the DataSource. I'm not an expert, but this is
where I would look at solving your problem. I think there is a
"DefaultStyle" property on the grid you could look at. Or does the
IBindingList interface supply a "Name" property? This must match the
mapping name of the style you have.

An excellent article on the innerworkings of the DataGrid and how it binds
to a datasource, is by Chris Sano.
http://msdn.microsoft.com/smartclie...n-us/dnwinforms/html/datagridcolumnstyle1.asp
 
if you want to read up on DataGrids, I really suggest you find that article.
It is really well written, and will give you a strong foundation for using
the grid, which I think is a pretty complicated UI tool. Google Chris Sano
and " Styling with the DataGridColumnStyle".

As for your style not being applied, I checked your source, and although you
are changing your datasource, you are not telling the Table Style to be
applied to the new datasource... it will only be applied to a datasource
named "ArrayList". If you change this to "clsGridRows", it will style as
expected. This is because, for example with a DataSet, you can have several
tables viewable through a DataGrid, and each table can have its own style,
so when the grid displays a table, it looks for a style that matches the
table, or provides a default style if it isn't found. So, you switched the
datasource, but the style was still looking for the arraylist.
 
Fantastic! Thank you so much. "If you change this to 'clsGridRows'" was
exactly the sentence i have been scouring the internet for 3 days to read. I
have made the appropriate changes to my code and the writers block has
passed.
Thanks,
Matt

PS. i read with interest the article you advised and i will be using some of
the techniques at a later stage in my project.
 

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

Back
Top