By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,889 Members | 1,373 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,889 IT Pros & Developers. It's quick & easy.

datagrid bound to IBindingList problem

P: n/a
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
Nov 17 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
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/smartclien...lumnstyle1.asp
"Matthew Woods" <mw****@bearwagner.com> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
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

Nov 17 '05 #2

P: n/a
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.
"Matthew Woods" <mw****@bearwagner.com> wrote in message
news:um**************@TK2MSFTNGP11.phx.gbl...
Thanks John, i didn't have too much success with the link you provided so
i
have zipped up a test project which highlights the problem. when i comment
out lines labeled "Method 2" i am binding an arraylist to the grid which
correctly applies the "CustomStyle()" but when i start the timer to change
the data the grid is only updated if i uncomment the datagrid1.refresh();
line in the timer.
when lines marked Method 1 are commented out and Method 2 are uncommented,
the grid refreshes correctly (without the need for a datagrid1.refresh())
because the ListChangedEvent is fired correctly BUT i cannot set the
style.

perhaps you (or anyone else for that matter, all help appreciated) could
take a quick look at the code, add any appropriate changes and re-post the
code.

Thanks
Matt

"John Richardson" <j3**********@hotmail.com> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
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/smartclien...lumnstyle1.asp


"Matthew Woods" <mw****@bearwagner.com> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
> 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
>
>



Nov 17 '05 #3

P: n/a
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.

"John Richardson" <j3**********@hotmail.com> wrote in message
news:ec**************@TK2MSFTNGP10.phx.gbl...
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.
"Matthew Woods" <mw****@bearwagner.com> wrote in message
news:um**************@TK2MSFTNGP11.phx.gbl...
Thanks John, i didn't have too much success with the link you provided so i
have zipped up a test project which highlights the problem. when i comment out lines labeled "Method 2" i am binding an arraylist to the grid which
correctly applies the "CustomStyle()" but when i start the timer to change the data the grid is only updated if i uncomment the datagrid1.refresh(); line in the timer.
when lines marked Method 1 are commented out and Method 2 are uncommented, the grid refreshes correctly (without the need for a datagrid1.refresh()) because the ListChangedEvent is fired correctly BUT i cannot set the
style.

perhaps you (or anyone else for that matter, all help appreciated) could
take a quick look at the code, add any appropriate changes and re-post the code.

Thanks
Matt

"John Richardson" <j3**********@hotmail.com> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
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/smartclien...lumnstyle1.asp

"Matthew Woods" <mw****@bearwagner.com> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
> 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
>
>



Nov 17 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.