wouter devinck


In windows form 2.0 I was using the following code:

Private Sub AddItemToGrid(ByVal col1 As String, ByVal col2 As String, ByVal col3 As String, ByVal col4 As String)

Dim tmp As New ListViewItem

tmp.Text = col1





End Sub

While migrating to WPF I figured out that this doesn't work anymore. I can't find anything about it on the web. Does anybody know how to do this in WPF using VB

Thanks in advance!

Re: Windows Presentation Foundation (WPF) How can I add an item to a listview in wpf

Nishant Sivakumar

Something like this should work :-

public struct NamePhone
  public NamePhone(string _name, string _phone)
    name = _name;
    phone = _phone;
  string name;
  public string Name
    get { return name; }
    set { name = value; }
  string phone;
  public string Phone
    get { return phone; }
    set { phone = value; }

  GridView view = new GridView();

  GridViewColumn col1 = new GridViewColumn();
  col1.Header = "Name";
  col1.DisplayMemberBinding = new Binding("Name");

  GridViewColumn col2 = new GridViewColumn();
  col2.Header = "Phone";
  col2.DisplayMemberBinding = new Binding("Phone");

  listView1.View = view;

  listView1.Items.Add(new NamePhone("Nish", "777"));
  listView1.Items.Add(new NamePhone("Alex", "555"));

Re: Windows Presentation Foundation (WPF) How can I add an item to a listview in wpf

Suprotim Agarwal

Dear Wouter,

I would also suggest you to explore ListView creation using XAML. ListView derives from ListBox with the difference that it uses Extended SelectionMode.

Also explore its View property (ViewBase class) to use Gridview inside listview and achieve some interesting results.


Suprotim Agarwal