开发者

Working with ListView in C++

I got a stupid question on ListView Control usage. I created a Windows Form App in VS2005. No I dragged a ListView Control from the toolbox. I want to implement my code to show some content(including both columns and rows). I know a little of MFC knowledge. I am not sure I must study the past MFC CListCtrol knowledge to implement my application or I can just study the System.Windows.Forms::ListView simply.

I found a good sample working with ListView (but wrote in C#). Can I translate the sample code from C# to C++ in VS2005? If I can. Could you please give me some suggestions?

using System;
using System.Windows.Forms;
using System.Drawing;

public class ListView1 : Form {
  ListView listView = new ListView();

  public ListView1() {
    listView.Dock = DockStyle.Fill;
    PopulateListView();
    this.Controls.Add(listView);
    this.ClientSize = new Size(400, 200);
  }


  private void PopulateListView() {
    // Set the view to show details.
    listView.View = View.Details;

    // Add columns
    listView.Columns.Add("Author", 
                         -2, 
                         HorizontalAlignment.Center);
    listView.Columns.Add("Title", 
                         -2, 
                         HorizontalAlignment.Left);
    listView.Columns.Add("Price", 
                         -2, 
                         HorizontalAlignment.Left);

    // Add items
    ListViewItem item1 = new ListViewItem("Steve Martin");
    item1.SubItems.Add("Programming .NET");
    item1.SubItems.Add("39.95");

    ListViewItem item2 = new ListViewItem("Irene Suzuki");
    item2.SubItems.Add("VB.NET Core Studies");
    item2.SubItems.Add("69.95");

    ListViewItem item3 = new ListViewItem("Ricky Ericsson");
    item3.SubItems.Add("Passing Your .NET Exams");
    item3.SubItems.Add("19.95")开发者_JAVA百科;

    // Add the items to the ListView.
    listView.Items.AddRange(
                            new ListViewItem[] {item1, 
                                                item2, 
                                                item3}
                            );
  }

  public static void Main() {
    ListView1 form = new ListView1();
    Application.Run(form);
  }
}


Actually you don't need that much of your previous knowledge of MFC to implement ListView. C++ under .NET (in layman terms means WinForm applications), you can almost seamlessly translate C# code to C++. If I understood your question correctly, what you need to do is to make sure how objects and properties are accessed in C++ if you are developing a winforms app. Like in C# if you have Object.function, in C++ you may need to write Object::function, this is just an example. Definitely you would need to some more in depth knowledge to run things seamlessly.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜