C# isn't that different from C++/MFC. Do you have Visual Studio ? It creates code for you if you select columns. This is the code Visual Studio creates for a simple ListView ( can't have a listbox with multiple columns ) adds two columns and the first line.
You will notice that the basics are the same:
createlistview
add column
add column
add item
set subitem for second column of item
PHP Code:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
namespace WindowsApplication2
{
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.ColumnHeader m_ColumnHeaderTwo;
private System.Windows.Forms.ColumnHeader m_ColumnHeaderOne;
private System.Windows.Forms.ListView m_ListView;
private System.ComponentModel.Container components = null;
public Form1()
{
InitializeComponent();
}
/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
System.Windows.Forms.ListViewItem listViewItem1 = new System.Windows.Forms.ListViewItem(new string[] {
"Test Text in Column One",
"Test Text in Column2 "}, -1, System.Drawing.SystemColors.WindowText, System.Drawing.SystemColors.Window, new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0))));
this.m_ListView = new System.Windows.Forms.ListView();
this.m_ColumnHeaderTwo = new System.Windows.Forms.ColumnHeader();
this.m_ColumnHeaderOne = new System.Windows.Forms.ColumnHeader();
this.SuspendLayout();
//
// m_ListView
//
this.m_ListView.Columns.AddRange(new System.Windows.Forms.ColumnHeader[] {
this.m_ColumnHeaderOne,
this.m_ColumnHeaderTwo});
this.m_ListView.Items.AddRange(new System.Windows.Forms.ListViewItem[] {
listViewItem1});
this.m_ListView.Location = new System.Drawing.Point(80, 80);
this.m_ListView.Name = "m_ListView";
this.m_ListView.Size = new System.Drawing.Size(160, 97);
this.m_ListView.TabIndex = 0;
this.m_ListView.View = System.Windows.Forms.View.Details;
//
// m_ColumnHeaderTwo
//
this.m_ColumnHeaderTwo.Text = "Second Column";
this.m_ColumnHeaderTwo.Width = 72;
//
// m_ColumnHeaderOne
//
this.m_ColumnHeaderOne.Text = "First Column";
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(292, 273);
this.Controls.AddRange(new System.Windows.Forms.Control[] {
this.m_ListView});
this.Name = "Form1";
this.Text = "Form1";
this.ResumeLayout(false);
}
#endregion
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new Form1());
}
}
}