Ask a questionAsk a question
 

AnswerAdding "sub items" to listview

  • Wednesday, November 04, 2009 10:37 AMUlab_newbie Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Hi all,
    i have a list view with tree columns and i need to add items to it like this

    ------------------------------------------
    Name            | Manufacturer | Cost
    ------------------------------------------
    Honda City    | Honda           | n$
    Honda Civic   | Honda           | n$
    Ford Icon       | Ford             | n$
    ------------------------------------------

    but im struck while adding Columns to it.i could not find ListViewItem.SubItem to add...

    can any one help me doing it.
    bals

Answers

  • Wednesday, November 04, 2009 12:53 PMUlab_newbie Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer

    thank you geert van and Rahul,
    i just did it by refering the this site : http://www.switchonthecode.com/tutorials/wpf-tutorial-using-the-listview-part-1
    this is what exactly iwanted to do.


    bals
  • Wednesday, November 04, 2009 12:57 PMMahesh Sabnis Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer
    Hi,

      Create a DataTemmpate with Grid inside it. Divide this Grid into 3 coulmns and then for each column put the TextBlocks bind with the concerned input values.

     

     

    <Window.Resources>

    <DataTemplate x:Key="EmpData">

    <Grid Width="300" ShowGridLines="True">

    <Grid.ColumnDefinitions>

    <ColumnDefinition Width="60"></ColumnDefinition>

    <ColumnDefinition Width="100"></ColumnDefinition>

    <ColumnDefinition Width="60"></ColumnDefinition>

    <ColumnDefinition Width="60"></ColumnDefinition>

    </Grid.ColumnDefinitions>

    <TextBlock Text="{Binding Path=EmpNo}" Grid.Column="0"></TextBlock>

    <TextBlock Text="{Binding Path=EmpName}" Grid.Column="1"></TextBlock>

    <TextBlock Text="{Binding Path=DeptNo}" Grid.Column="2" TextAlignment="Center"></TextBlock>

    <TextBlock Text="{Binding Path=Salary}" Grid.Column="3"></TextBlock>

    </Grid>

    </DataTemplate>

    </Window.Resources>

    <Grid Width="300">

    <ListView Margin="4,17,20,0" Name="listBox1" Width="300"

    ItemsSource="{Binding}" ItemTemplate="{StaticResource EmpData}"/>

    </Grid>


    Mahesh Sabnis

All Replies

  • Wednesday, November 04, 2009 10:52 AMGeert van Horrik Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    In your listview, there is a ListView.View property. Put a GridView in there.

    A detailed explanation can be found in this blog article.
    Geert van Horrik - CatenaLogic
    Visit my blog: http://blog.catenalogic.com

    Looking for a way to deploy your updates to all your clients? Try Updater!
  • Wednesday, November 04, 2009 10:57 AMRahul P Nath Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Hi,
    See if it is something like this you are looking for .
    By default you want get such an option.You will have to change the templates,so as to suite your requirement.
    The above representation doesnt make it clear to me on how you want the data to be.I see only a single level of data.

    Could you please make it more clear so that i may be of more help

    Thank You


    Please mark posts as answers/helpful if it answers your query. This would be helpful for others facing the same kind of problem
  • Wednesday, November 04, 2009 12:53 PMUlab_newbie Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer

    thank you geert van and Rahul,
    i just did it by refering the this site : http://www.switchonthecode.com/tutorials/wpf-tutorial-using-the-listview-part-1
    this is what exactly iwanted to do.


    bals
  • Wednesday, November 04, 2009 12:57 PMMahesh Sabnis Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer
    Hi,

      Create a DataTemmpate with Grid inside it. Divide this Grid into 3 coulmns and then for each column put the TextBlocks bind with the concerned input values.

     

     

    <Window.Resources>

    <DataTemplate x:Key="EmpData">

    <Grid Width="300" ShowGridLines="True">

    <Grid.ColumnDefinitions>

    <ColumnDefinition Width="60"></ColumnDefinition>

    <ColumnDefinition Width="100"></ColumnDefinition>

    <ColumnDefinition Width="60"></ColumnDefinition>

    <ColumnDefinition Width="60"></ColumnDefinition>

    </Grid.ColumnDefinitions>

    <TextBlock Text="{Binding Path=EmpNo}" Grid.Column="0"></TextBlock>

    <TextBlock Text="{Binding Path=EmpName}" Grid.Column="1"></TextBlock>

    <TextBlock Text="{Binding Path=DeptNo}" Grid.Column="2" TextAlignment="Center"></TextBlock>

    <TextBlock Text="{Binding Path=Salary}" Grid.Column="3"></TextBlock>

    </Grid>

    </DataTemplate>

    </Window.Resources>

    <Grid Width="300">

    <ListView Margin="4,17,20,0" Name="listBox1" Width="300"

    ItemsSource="{Binding}" ItemTemplate="{StaticResource EmpData}"/>

    </Grid>


    Mahesh Sabnis

  • Wednesday, November 04, 2009 1:05 PMRahul P Nath Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Hi,
    So here actually there is no SubItems :)
    It was just that you wanted to add items to the listview :)
    Anyways good that your problem is solved


    Please mark posts as answers/helpful if it answers your query. This would be helpful for others facing the same kind of problem
  • Thursday, November 05, 2009 6:53 AMUlab_newbie Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    yes,there is no subitems.
    im confused with windows forms controls with WPF.
    wpf is quite different with those controls.i think it takes a while for me to be confortable with WPF :)


    bals