Multicolumn ListView in WPF - errors
- by Will
Hi, I am trying to define a multicolumn listview in xaml (visual studio 2008) and then add items to it in c#. I have seen many posts on this subject, and tried the various methods, but I am getting errors.
my xaml code is below, VS does not flag any errors on it.
<ListView Height="234.522" Name="chartListView" Width="266.337">
<ListView.View>
<GridView>
<GridViewColumn Header="Name" Width="70"/>
<GridViewColumn Header="ID" />
</GridView>
</ListView.View>
</ListView>
to try and add data to the columns,
I created a button and put the code in the button click :
private void button3_Click(object sender, RoutedEventArgs e)
{
chartListView.Items.Add("item1").SubItems.Add("item2");
}
the error that is showing is on Subitems is:
'int' does not contain a definition for 'SubItems' and no extension method 'SubItems' accepting a first argument of type 'int' could be found (are you missing a using directive or an assembly reference?) D:\devel\VS\pchart\pchart\pchart\Window1.xaml.cs
Also, I tried looking at some other posts on listview controls such as
http://stackoverflow.com/questions/1260812/listview-inserting-items
i tried the code there :
ListViewItem item = new ListViewItem();
item.Text=anInspector.getInspectorName().ToString();
and got almost the same error on item.Text as i did with SubItems. is there something earlier in my code, or project definition that i am missing?
Thanks for any help