DataGrid Default Column Style

  • Thread starter Andrew Armstrong
  • Start date
A

Andrew Armstrong

I have a datagrid where I want to hide a couple of the columns. To do this I
have added a Table style with two DataGridTextBoxColumn and set their widths
to 0 and MappingName property to the names of the Columns I want to hide.
This achieves the required effect. However when I had a new Column without a
style mapped to it the Column does not appear in the DataGrid. If I am using
TableStyles do I have to define a style for each Column or is there a way of
setting a default style.



I would be grateful for any help or insight into this problem. I am sure it
is possible I just don't know how.



Many Thanks



Andrew
 
Y

Ying-Shen Yu[MSFT]

Hi Andrew,

If you defined a TableStyle for a data table, DataGrid will only use the
defined TableStyle to display the datatable. Default table style will not
take effect.
So you need add all the columnstyles needed to the TableStyle object before
adding the tablestyle to the TableStyles collection*.

* as MSDN documentation states:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/
frlrfsystemwindowsformsdatagridcolumnstyleclasstopic.asp
<cite>
CAUTION Always create DataGridColumnStyle objects and add them to the
GridColumnStylesCollection before adding DataGridTableStyle objects to the
GridTableStylesCollection. When you add an empty DataGridTableStyle to the
collection, DataGridColumnStyle objects are automatically generated for
you. Consequently, an exception will be thrown if you try to add new
DataGridColumnStyle objects with duplicate MappingName values to the
GridColumnStylesCollection.

</cite>


Thanks!

Best regards,

Ying-Shen Yu [MSFT]
Microsoft community Support
Get Secure! - www.microsoft.com/security

This posting is provided "AS IS" with no warranties and confers no rights.
This mail should not be replied directly, please remove the word "online"
before sending mail.
 
A

Andrew Armstrong

Thanks

That clears up what I can and can't do with Table Style's.

Andrew
 

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