Click here to Skip to main content
15,881,559 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi,
This might be a silly question but im a beginner so im not sure. I have 3 lists and i am displaying them on 3 different listboxes in a listview as follows:

public System.Collections.ArrayList name
       {
           get
           {
               return _name;
           }

       }
       public System.Collections.ArrayList path
       {
           get
       {
               return _path;
       }

       }
       public System.Collections.ArrayList size
       {
           get
           {
               return _size;
           }

       }


Corresponding xml:

<pre lang="HTML"><listview.view>
                    <gridview>
                        <gridviewcolumn>
                            Width="270" 
                            Header="File Name">
                            <gridviewcolumn.celltemplate>
                                <datatemplate>
                                    <!--<listbox name="listbox_name" itemssource="{Binding s}" />-->
                                    <listbox itemssource="{Binding Path= name}" issynchronizedwithcurrentitem="True" />    
                                </datatemplate>
                            </gridviewcolumn.celltemplate>
                        </gridviewcolumn>
                        <gridviewcolumn>
                            Width="270" 
                            Header="File Path">
                            <gridviewcolumn.celltemplate>
                                <datatemplate>
                                    <!--<listbox name="listbox_path" itemssource="{Binding abcdf}" />-->
                                    <listbox itemssource="{Binding Path= path}" issynchronizedwithcurrentitem="True" />
                                </datatemplate>
                            </gridviewcolumn.celltemplate>
                        </gridviewcolumn>
                        <gridviewcolumn>
                            Width="200" 
                            Header="File Size">
                            <gridviewcolumn.celltemplate>
                                <datatemplate>
                                    <!--<listbox name="listbox_size" />-->
                                    <listbox itemssource="{Binding Path= size}" issynchronizedwithcurrentitem="True" />
                                </datatemplate>
                            </gridviewcolumn.celltemplate>
                        </gridviewcolumn>
                    </gridview>
                </listview.view>


But i dont see any result! I think im making a basic mistake, not able to figure it out :( Please help me! thanks :)
Posted
Comments
BobJanova 2-Nov-11 6:12am    
Did you set the binding context of the list view, or something in its parentage tree, to the object which exposes these properties?

Why are you using ArrayList, not List<T>? (Or even BindingList<T>.)
bizzare1988 2-Nov-11 6:15am    
@bobjanova: im sorry, i dont get what you mean :( Ive posted all i've done.
BobJanova 2-Nov-11 7:34am    
In WPF/Silverlight, controls, or the page as a whole, have a BindingContext (which defaults to the page class itself, if I remember right). Did you set that here? Can you bind something else in the same XAML to a simple property in the class (i.e. is the binding looking at the right target)?

Nothing appearing in a list could mean that the binding target is null or zero-length; make sure you actually put something into these lists!

ArrayList is an old, pre-generic collection, and unless you're putting things of unknown type in there (even then it may be better to use List<object>) you should use a typed list, e.g. List<string> names, List<int> sizes.

Kindly check the data is there while binding your collection..
 
Share this answer
 
Comments
bizzare1988 2-Nov-11 23:30pm    
Hi Pandya,
Yes the data is there while binding.

Did you set the DataContext of your window?


If you declared the properties in the window's class, you can set the DataContext to the window. Just add this line:


C#
DataContext = this;

to the constructor of the window's class.


But, it is better to declare the properties in a different class and, set the DataContext to that class. For more details, read about MVVM.


Another issue is the type of the collection. If you replace the ArrayList with an ObservableCollection, your view also will be notified about the collection's changes.

 
Share this answer
 
Comments
bizzare1988 2-Nov-11 23:41pm    
Hi Shmuel,I did try this but it doesn't work still :( Im actually in a hurry and cant really change my code now :( I'll try changing it to observable collection. Thanks! Is there any other way i coudl go about?
Great! i got it by using the solution posted here: http://www.switchonthecode.com/tutorials/wpf-tutorial-using-the-listview-part-1[^]
 
Share this answer
 

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