tags:

views:

26

answers:

2

I have a XAML file with only a ListBox. I dynamically create the columns and add the rows. with this code:

ListBoxItem l1 = new ListBoxItem();
StackPanel s1 = new StackPanel(); 
s1.Orientation = Orientation.Horizontal;
ContentPresenter ch1 = new ContentPresenter();
ch1.Content = "ICR";
s1.Children.Add(ch1); //just an example I add more than 1 column
li.Content = s1; 
listbox.items.add(l1); 

Which works fine, but now I want to create column headers and sort by column. Can I do that with a dynamically with a ListBox or am I going down the wrong path?

+1  A: 

If you want multiple columns and column headers, don't use a ListBox... use a ListView or a DataGrid instead.

As for sorting, you will probably have to do it manually, because of the way you fill the list. It would be much easier if you were using data binding. About everything in WPF is easier when you start using binding...

Thomas Levesque