Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > Avalon

Vista Tutorial - Manual population of listview

 
 
Old 05-29-2007   #1 (permalink)
Radek Cerny
Guest


 
 

Manual population of listview

Hi,

pulling out whats left of my hair...

Assuming I have a simple xaml file with a listview, or even some other
placeholder, does anyone have simple code to demonstrate manual (eg cell by
cell, row by row) population of a listview?

I can certainly programmatically create all I need including GridViewColumn
headers and ListViewItem objects, BUT ListViewItem exposes only a simple
Content property of type object, and I can not figure out how to provide the
cell information to correspond with the column/header definitions.

Can anyone help please!?



My System SpecsSystem Spec
Old 05-29-2007   #2 (permalink)
Plamen Ratchev
Guest


 
 

Re: Manual population of listview

Normally you specify the content of the ListView by setting the ItemSource
property of the Items property. You can see good examples of that here:
http://msdn2.microsoft.com/en-us/lib....listview.aspx
http://blogs.msdn.com/atc_avalon_tea...23/537715.aspx

Alternatively you can add row by row, a brief step by step here:

1. Assuming you have a custom class (Employee) that exposes properties for
FirstName and LastName.
2. Add two GridView columns.
3. On the first one set col1.DisplayMemberBinding = new
Binding("FirstName");
4. On the second one set col2.DisplayMemberBinding = new
Binding("LastName");
5. Create an instance of your custom object, like:
Employee emp = new Employee();
emp.FirstName = "Joe";
emp.LastName = "Doe";
// Next add to the ListView
MyListView.Items.Add(emp);

That should do it.

HTH,

Plamen Ratchev
http://www.SQLStudio.com



My System SpecsSystem Spec
Old 05-29-2007   #3 (permalink)
Radek Cerny
Guest


 
 

Re: Manual population of listview

Hi,

thanks for that. I am glad someone is listening. My problem is one of
abstraction and UI - Business Object separation.

I have a sever that exposes only Web Services, and behind that of course is
a wonderful world of Business Objects, ORM, etc.

Now on the client I have WPF - the Presentation Layer. I need to be able to
handle very dynamic data on the client; the Business Objects do not exist
client side - only the data. The WebService may publish an XML document
that carries data+metadata (eg column Names/types/widths etc). I need to
respond to the metadata by dynamically creating columns in the GridView, and
publishing the data as well. All formatting, business rule execution etc
happens on the server. The client only has a remote URL to talk to, and is
very very "thin".

I have managed to get a XmlDataProvider working, but now I am having trouble
with Templates; is there a programmatic way of creating a DataTemplate with
dynamic binding?

Cheers, and thanks again,

Radek


"Plamen Ratchev" <Plamen@SQLStudio.com> wrote in message
news:Odn04BgoHHA.4512@TK2MSFTNGP03.phx.gbl...
> Normally you specify the content of the ListView by setting the ItemSource
> property of the Items property. You can see good examples of that here:
> http://msdn2.microsoft.com/en-us/lib....listview.aspx
> http://blogs.msdn.com/atc_avalon_tea...23/537715.aspx
>
> Alternatively you can add row by row, a brief step by step here:
>
> 1. Assuming you have a custom class (Employee) that exposes properties for
> FirstName and LastName.
> 2. Add two GridView columns.
> 3. On the first one set col1.DisplayMemberBinding = new
> Binding("FirstName");
> 4. On the second one set col2.DisplayMemberBinding = new
> Binding("LastName");
> 5. Create an instance of your custom object, like:
> Employee emp = new Employee();
> emp.FirstName = "Joe";
> emp.LastName = "Doe";
> // Next add to the ListView
> MyListView.Items.Add(emp);
>
> That should do it.
>
> HTH,
>
> Plamen Ratchev
> http://www.SQLStudio.com
>
>
>



My System SpecsSystem Spec
Old 05-29-2007   #4 (permalink)
Plamen Ratchev
Guest


 
 

Re: Manual population of listview

You can programmatically use the DataTemplate class. First you have to
create the VisualTree of elements for the template and then you can
dynamically bind your XML data.

Here are two examples, I believe the combination of both will give you all
necessary to understand and implement the concept:
http://dedjo.blogspot.com/2007/03/cr...from-code.html
http://blogs.microsoft.co.il/blogs/t...detection.aspx

HTH,

Plamen Ratchev
http://www.SQLStudio.com



My System SpecsSystem Spec
Old 05-29-2007   #5 (permalink)
Radek Cerny
Guest


 
 

Re: Manual population of listview

Hi Plamen,

I've had a quick look at the links and they look very promising... will keep
you posted.

Cheers,

Radek

"Plamen Ratchev" <Plamen@SQLStudio.com> wrote in message
news:u%23MomDmoHHA.3460@TK2MSFTNGP04.phx.gbl...
> You can programmatically use the DataTemplate class. First you have to
> create the VisualTree of elements for the template and then you can
> dynamically bind your XML data.
>
> Here are two examples, I believe the combination of both will give you all
> necessary to understand and implement the concept:
> http://dedjo.blogspot.com/2007/03/cr...from-code.html
> http://blogs.microsoft.co.il/blogs/t...detection.aspx
>
> HTH,
>
> Plamen Ratchev
> http://www.SQLStudio.com
>
>
>



My System SpecsSystem Spec
 

Thread Tools



Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46