Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. WPF
  4. Display list content

Display list content

Scheduled Pinned Locked Moved WPF
questiontutorialcsharpwpf
10 Posts 5 Posters 2 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    columbos14927
    wrote on last edited by
    #1

    Hello, Is there some control in WPF that i can use to display a list. For example i have a list of objects where each object have some number of properties. I wannt to give this list to the control and he will display each object properties in a row when every propertie displayed in a separate column. So my question is is there some control already in WPF. If not i will have some how to create one but in order to create i have to know how many properties object has,how can i do it? Thanks.

    P M L 3 Replies Last reply
    0
    • C columbos14927

      Hello, Is there some control in WPF that i can use to display a list. For example i have a list of objects where each object have some number of properties. I wannt to give this list to the control and he will display each object properties in a row when every propertie displayed in a separate column. So my question is is there some control already in WPF. If not i will have some how to create one but in order to create i have to know how many properties object has,how can i do it? Thanks.

      P Offline
      P Offline
      Pete OHanlon
      wrote on last edited by
      #2

      You could use a DataGrid and set AutoGenerateColumns="True" on it. This assumes that all your properties can be displayed textually - if you have images to display, for instance, you are going to have to take over control yourself. WPF can only go so far.

      Forgive your enemies - it messes with their heads

      "Mind bleach! Send me mind bleach!" - Nagy Vilmos

      My blog | My articles | MoXAML PowerToys | Mole 2010 - debugging made easier - my favourite utility

      1 Reply Last reply
      0
      • C columbos14927

        Hello, Is there some control in WPF that i can use to display a list. For example i have a list of objects where each object have some number of properties. I wannt to give this list to the control and he will display each object properties in a row when every propertie displayed in a separate column. So my question is is there some control already in WPF. If not i will have some how to create one but in order to create i have to know how many properties object has,how can i do it? Thanks.

        M Offline
        M Offline
        Member 1033907
        wrote on last edited by
        #3

        Check out ListView, it is customizable to some degree (with AutoGenerateColumns=false) and it will probably serve you just fine.

        1 Reply Last reply
        0
        • C columbos14927

          Hello, Is there some control in WPF that i can use to display a list. For example i have a list of objects where each object have some number of properties. I wannt to give this list to the control and he will display each object properties in a row when every propertie displayed in a separate column. So my question is is there some control already in WPF. If not i will have some how to create one but in order to create i have to know how many properties object has,how can i do it? Thanks.

          L Offline
          L Offline
          Lost User
          wrote on last edited by
          #4

          If you want to auto render then as Pete suggested your best bet is the DataGrid. If however you need more complex displays you can use the ListView and make DataTemplates for the more complicated properties. Then also a data template for the parent property. For example say I have an object Employee and with in it I have full name, pay grade, contact info, and picture. I would likely in the parent object have a collection of employees of which the listview has its itemsource bound to.

          So this defines our Employee collection and how we want Employee to render. However, we have not defined how the properties should be rendered. This is good and bad. By default, if it is a string (e.g. Name) it will display the string. Otherwise it will ToString the object. In this case we want to make DataTemplates for those objects as well. A good example here is the ContactInfo. The contact info may just be Address. Or maybe it includes eMail and even an Instant Messenger contact ID. If these later items are included one could design a control that allows you to IM right from your grid. This is some of the beauty of views not caring about each other. They just know they want to 'show' object 'A'. How object 'A' is rendered is up to some other design/datatemplate.

          Computers have been intelligent for a long time now. It just so happens that the program writers are about as effective as a room full of monkeys trying to crank out a copy of Hamlet.

          M 1 Reply Last reply
          0
          • L Lost User

            If you want to auto render then as Pete suggested your best bet is the DataGrid. If however you need more complex displays you can use the ListView and make DataTemplates for the more complicated properties. Then also a data template for the parent property. For example say I have an object Employee and with in it I have full name, pay grade, contact info, and picture. I would likely in the parent object have a collection of employees of which the listview has its itemsource bound to.

            So this defines our Employee collection and how we want Employee to render. However, we have not defined how the properties should be rendered. This is good and bad. By default, if it is a string (e.g. Name) it will display the string. Otherwise it will ToString the object. In this case we want to make DataTemplates for those objects as well. A good example here is the ContactInfo. The contact info may just be Address. Or maybe it includes eMail and even an Instant Messenger contact ID. If these later items are included one could design a control that allows you to IM right from your grid. This is some of the beauty of views not caring about each other. They just know they want to 'show' object 'A'. How object 'A' is rendered is up to some other design/datatemplate.

            Computers have been intelligent for a long time now. It just so happens that the program writers are about as effective as a room full of monkeys trying to crank out a copy of Hamlet.

            M Offline
            M Offline
            Member 1033907
            wrote on last edited by
            #5

            What is the difference/benefit between this and using ListBox? I thought ListView was supposed to be used with views (ViewBase-derived objects), like GridView - isn't that the case?

            L 1 Reply Last reply
            0
            • M Member 1033907

              What is the difference/benefit between this and using ListBox? I thought ListView was supposed to be used with views (ViewBase-derived objects), like GridView - isn't that the case?

              L Offline
              L Offline
              Lost User
              wrote on last edited by
              #6

              There really is not much difference. ListView is a listbox but is defaulted to Extended mode vs Single. I am not sure what you mean by "supposed to be used with views (ViewBase-derived objects), like GridView. Both ListView and ListBox contain collections. How they are rendered is determined by the ItemTemplate, which is editable by the user.

              Computers have been intelligent for a long time now. It just so happens that the program writers are about as effective as a room full of monkeys trying to crank out a copy of Hamlet.

              M S 2 Replies Last reply
              0
              • L Lost User

                There really is not much difference. ListView is a listbox but is defaulted to Extended mode vs Single. I am not sure what you mean by "supposed to be used with views (ViewBase-derived objects), like GridView. Both ListView and ListBox contain collections. How they are rendered is determined by the ItemTemplate, which is editable by the user.

                Computers have been intelligent for a long time now. It just so happens that the program writers are about as effective as a room full of monkeys trying to crank out a copy of Hamlet.

                M Offline
                M Offline
                Member 1033907
                wrote on last edited by
                #7

                What I meant (and also in my replay to OP) is that ListView (as opposed to ListBox) can be used this way

                <ListView>
                <ListView.View>
                <GridView>
                <GridViewColumn DisplayMemberBinding="{Binding FirstName}" Header="First Name" />
                ...
                </GridView>
                <ListView.View>
                </ListView>

                where the individual columns can be either autogenerated or more or less customized. Which I assume is what the OP wanted. This displays the "grid-view" known for example from file explorer if you select display mode->details. This is (I think) the primary purpose of ListView.

                L 1 Reply Last reply
                0
                • M Member 1033907

                  What I meant (and also in my replay to OP) is that ListView (as opposed to ListBox) can be used this way

                  <ListView>
                  <ListView.View>
                  <GridView>
                  <GridViewColumn DisplayMemberBinding="{Binding FirstName}" Header="First Name" />
                  ...
                  </GridView>
                  <ListView.View>
                  </ListView>

                  where the individual columns can be either autogenerated or more or less customized. Which I assume is what the OP wanted. This displays the "grid-view" known for example from file explorer if you select display mode->details. This is (I think) the primary purpose of ListView.

                  L Offline
                  L Offline
                  Lost User
                  wrote on last edited by
                  #8

                  Good to know, I guess I never realized that. Thank you. :)

                  Computers have been intelligent for a long time now. It just so happens that the program writers are about as effective as a room full of monkeys trying to crank out a copy of Hamlet.

                  1 Reply Last reply
                  0
                  • L Lost User

                    There really is not much difference. ListView is a listbox but is defaulted to Extended mode vs Single. I am not sure what you mean by "supposed to be used with views (ViewBase-derived objects), like GridView. Both ListView and ListBox contain collections. How they are rendered is determined by the ItemTemplate, which is editable by the user.

                    Computers have been intelligent for a long time now. It just so happens that the program writers are about as effective as a room full of monkeys trying to crank out a copy of Hamlet.

                    S Offline
                    S Offline
                    SledgeHammer01
                    wrote on last edited by
                    #9

                    There is a huge difference between ListView and ListBox. ListBox just displays a flat list of items whereas ListView supports columns, grouping, etc.

                    L 1 Reply Last reply
                    0
                    • S SledgeHammer01

                      There is a huge difference between ListView and ListBox. ListBox just displays a flat list of items whereas ListView supports columns, grouping, etc.

                      L Offline
                      L Offline
                      Lost User
                      wrote on last edited by
                      #10

                      Seems like you are just nit picking now. The differences are subtle at best. ListView inherits from ListBox. ListView just exposes View as was pointed out. To say their is a 'huge' difference is odd since they essentially are the same except for this feature. Granted a nice feature, but hardly a 'huge' difference. http://msdn.microsoft.com/en-us/library/system.windows.controls.listview.aspx[^]

                      Computers have been intelligent for a long time now. It just so happens that the program writers are about as effective as a room full of monkeys trying to crank out a copy of Hamlet.

                      1 Reply Last reply
                      0
                      Reply
                      • Reply as topic
                      Log in to reply
                      • Oldest to Newest
                      • Newest to Oldest
                      • Most Votes


                      • Login

                      • Don't have an account? Register

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • World
                      • Users
                      • Groups