Click here to Skip to main content
15,885,757 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello,
I'm a newbie to WPF and having troubles to figure out how to hide or show a column based on its data

I currently have a list view as


HTML
<listview>
     <listview.view>
       <gridviewcolumn header="Code " width="50">
          <gridviewcolumn.celltemplate>
              <datatemplate>
                    <textblock text="{Binding Path=Code}" textalignment="Center" />
               </datatemplate>
          </gridviewcolumn.celltemplate>
       </gridviewcolumn> 
 
        <gridviewcolumn header="" width="20">
            <gridviewcolumn.celltemplate>
               <datatemplate>
                   <textblock text="{Binding Path=CodeType}" textalignment="Center" />
                                                   
                                    </datatemplate>
                                </gridviewcolumn.celltemplate>
                            </gridviewcolumn>
</listview.view>
</listview>

I tried not to display the CodeType column when the data in the column is U and show it when data is S after I dynamically changed to datasource (ListView.dataContext = ds.Tables(0) .....ete)
for ex: my listview could show like:

Code CodeType
1-Empty S
2-Liquid
3-Rock S

the 2-Liquid has code type of U and not show U here.

Read lots of article here but still having errors and could not complete it.
Please let me know if you have an answer. Thanks a lot.
Posted
Comments
AspDotNetDev 8-Sep-11 16:09pm    
Sounds like you want a DataTrigger. You can set a Visibility property to Hidden when the data is set to some particular value. Update your question if you need help with that (Google should provide sufficient guidance).
dasblinkenlight 8-Sep-11 17:05pm    
The question does not make much sense to me: you refer to a "value of a column" as if it were singular, yet there may be many values in a column. A list view column holds potentially distinct values in each of its rows. Which of these many values would you like your code to use when making a decision to hide the column? Please edit your question to provide more clarity.
AspDotNetDev 9-Sep-11 14:40pm    
I think the OP means "field", not "column" (as demonstrated by the sample output).

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900