locked
Placing controls in ListView "cells" RRS feed

  • Question

  • Is it possible to mix and match content for ListView cells?

    For example, is there a syntax that will accomplish the following.

    <ListView>
     <ListView.View>
      <GridView>
       <GridViewColumn Header="A" Width="100"/>
       <GridViewColumn Header="B" Width="100"/>
       <GridViewColumn Header="C" Width="100"/>
      </GridView>
     </ListView.View>
     <ListViewItem>
      <Cell><TextBox/></Cell>
      <Cell><TextBox/></Cell>
      <Cell><CheckBox/></Cell>
     </ListViewItem>
     <ListViewItem>
      <Cell><RadioButton/></Cell>
      <Cell><RadioButton/></Cell>
      <Cell><Label/></Cell>
     </ListViewItem>
    </ListView>

    I think the main missing piece is what to put in place of the "Cell" tag, which clearly isn't a valid tag.

    Note that the kinds of controls in the second ListViewItem are different than those in the first ListViewItem. The controls will be determined row-by-row and can vary widely.

    Thursday, October 22, 2009 1:08 AM

Answers

  • You may want to try using a ContentTemplateSelector on each ListViewItem or alternatively use ItemTemplateSelector on the ListView itself. There might be other options available to you as well such as using converters to convert an object to an appropriate visual, but those depend on what logic needs to dictate what to show in each cell.
    - Matt Eland
    • Proposed as answer by Rahul P Nath Thursday, October 22, 2009 3:51 AM
    • Marked as answer by Zhi-Xin Ye Monday, October 26, 2009 1:40 PM
    Thursday, October 22, 2009 3:37 AM

All replies

  • You may want to try using a ContentTemplateSelector on each ListViewItem or alternatively use ItemTemplateSelector on the ListView itself. There might be other options available to you as well such as using converters to convert an object to an appropriate visual, but those depend on what logic needs to dictate what to show in each cell.
    - Matt Eland
    • Proposed as answer by Rahul P Nath Thursday, October 22, 2009 3:51 AM
    • Marked as answer by Zhi-Xin Ye Monday, October 26, 2009 1:40 PM
    Thursday, October 22, 2009 3:37 AM
  • I'm new to WPF.  Is there nothing that will work like my hypothetical "Cell" tag?

    No way to divide up a <ListViewItem/> into cells in the markup?
    Thursday, October 22, 2009 10:16 PM
  • Nope. Closest you you can get it is via content template and content template selector. Have a go with those.
    - Matt Eland
    Thursday, October 22, 2009 11:17 PM